Subject: Need help getting a PowerShell example working
This is what I have so far, having translated it from the C# Send Message example. No message is received, but I get no errors either. I have a feeling I didn't invoke the Send method correctly. Here is the C# line I'm having trouble with:
[Update: I worked with Alex on this and here is code that works pretty well, but not against all servers. You can see the various options I was playing with, they may help in your situation. The key was to loop for the state of $xmppClient.Authenticated.]
And the PowerShell code:
- xmpp.OnLogin += delegate(object o) { xmpp.Send(new Message(new Jid(JID_RECEIVER), MessageType.chat, "Hello, how are you?")); };
[Update: I worked with Alex on this and here is code that works pretty well, but not against all servers. You can see the various options I was playing with, they may help in your situation. The key was to loop for the state of $xmppClient.Authenticated.]
And the PowerShell code:
- function Send-XmppMessage {
- param (
- $From,
- $Password,
- $To,
- $Body
- )
- # This function reads a string from the host while masking with *'s.
- function Read-HostMasked( [string]$prompt="Password" ) {
- $password = Read-Host -AsSecureString $prompt;
- $BSTR = [System.Runtime.InteropServices.marshal]::SecureStringToBSTR($password);
- $password = [System.Runtime.InteropServices.marshal]::PtrToStringAuto($BSTR);
- [System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($BSTR);
- }
- [void][reflection.assembly]::LoadFrom( $(resolve-path $profiledir\Assemblies\agsXMPP.dll) )
- $jidSender = New-Object agsxmpp.jid( $From )
- $jidReceiver = New-Object agsxmpp.jid ( $To )
- $xmppClient = New-Object agsxmpp.XmppClientConnection( $jidSender.Server )
- $Message = New-Object agsXMPP.protocol.client.Message( $jidReceiver, $Body )
- #$xmppClient.UseSSL = $FALSE
- #$xmppClient.UseStartTLS = $FALSE
- $xmppClient.AutoAgents = $FALSE
- $xmppClient.AutoRoster = $FALSE
- $xmppClient.AutoResolveConnectServer = $TRUE
- if ( !$password ) { $password = Read-HostMasked }
- $xmppClient.Open( $jidSender.User, $Password )
- while ( !$xmppClient.Authenticated ) {
- Write-Host $xmppClient.XmppConnectionState
- Start-Sleep 1
- }
- #$xmppClient.SendMyPresence()
- $xmppClient.Send( $Message )
- Start-Sleep 1
- $xmppClient.Close()
- }
Author, TechProsaic (http://halr9000.com)
Co-Host, PowerScripting Podcast (http://powerscripting.net)
Webmaster, Psi (http://psi-im.org)
Co-Host, PowerScripting Podcast (http://powerscripting.net)
Webmaster, Psi (http://psi-im.org)
This post was edited on 2008-01-07, 20:17 by halr9000.