Dec
5
Written by:
SAPIENScripter
12/5/2007 9:22 AM
I use Windows Live Messenger so that my co-workers can contact me. Because we work in different time zones I break for lunch just about the time they are gearing up. I sometimes forget to set my status accordingly. Because I basically live at a shell prompt, I wanted a quick way to manage my Live Messenger status from PowerShell. Because PowerShell can work with COM objects, this is actually pretty easy to do.
$messenger=New-Object -com "Messenger.UIAutomation"
The Status property will return an integer that represents one of these constant values:
$MISTATUS_UNKNOWN=0>
$MISTATUS_ONLINE=2
$MISTATUS_BUSY=10
$MISTATUS_BE_RIGHT_BACK=14
$MISTATUS_IDLE=18
$MISTATUS_AWAY=34
$MISTATUS_ON_THE_PHONE=50
$MISTATUS_OUT_TO_LUNCH=66
I use a simple Switch statement to translate:
Switch ($messenger.Mystatus) {
$MISTATUS_UNKNOWN {$status = "in an unknown status"}
$MISTATUS_OFFLINE {$status = "offline"}
$MISTATUS_ONLINE {$status = "online"}
$MISTATUS_INVISIBLE {$status = "invisible"}
$MISTATUS_BUSY {$status = "busy"}
$MISTATUS_BE_RIGHT_BACK {$status = "busy and will be right back"}
$MISTATUS_IDLE {$status = "idle"}
$MISTATUS_AWAY {$status = "away"}
$MISTATUS_ON_THE_PHONE {$status = "on the phone"}
$MISTATUS_OUT_TO_LUNCH {$status = "out to lunch"}
Default {$status = " lost"}
}
write "I am $status
Changing my status is just as easy.
$messenger.myStatus=$MISTATUS_OUT_TO_LUNCH
I can use either the numeric value or the constant.
Now of course, I don't want to have to create objects all the time, so I created a few functions for getting and setting my Live Messenger status. They are in the attached file. The script also defines aliases since I like shortcuts.
You can't set your Live Messenger status unless you are logged in. Because I work at home I can get by with a little less security, so I wrote a function to bring up the logon window with my account and password. I enter the password in clear text at the prompt but because nobody is around I can live with that.
Function SignIn-Messenger {
Param ([string]$user,[string]$password)
$messenger=New-Object -com "Messenger.UIAutomation"
$messenger.Signin(0,$user,$password)
}
You still have to respond to the dialog box and press Enter. There is a method for automatic sign-on which would simply this even further, but because I travel and am often not connected to a network I've never set it up.
So far I've been happy with what I can do in PowerShell that keeps my hands on the keyboard. Hopefully you'll find this useful too.
manage-messenger.txt