Reboot a Polycom phone via PowerShell
Jeffrey Snover posted a while ago encouraging others to share their PowerShell automation, no matter how little. Well in the spirit of that post, here is a script that will reboot a Polycom IP phone; I tested it with the IP600. (Note: my script is based on the perl version found here.)
Essentially the script sends a SIP NOTIFY message to an IP phone, pretending to be from a registered server. Polycom phones respond to the “check-sync” event by re-comparing the config file last-modified date, and if newer, will reboot themselves (they will wait until the phone itself is idle–so don’t worry about the phone being on a call and suddenly rebooting).
Update: A commenter pointed out that my info on Polycom phones is a little outdated - the phones will do a file comparison on the beginning of the configuration files and update if they have changed. Glad to see it improving over time!
You can download the PowerShell version here.
1: ################################################################
2: ##
3: ## Script: Reboot-Polycom.ps1
4: ## By: Aaron Lerch
5: ## Website: www.aaronlerch.com/blog
6: ##
7: ## Issue a command to a Polycom phone to reboot itself
8: ##
9: ## Usage: Reboot-Polycom [ip address of phone] [ip address of server] [phone identifier]
10: ##
11: ## ie:
12: ##
13: ## PS:1 > Reboot-Polycom "10.0.0.1" "10.0.0.2" "12345"
14: ##
15: ################################################################
16:
17: param(
18: [System.Net.IPAddress] $phoneip,
19: [System.Net.IPAddress] $serverip,
20: [string] $phoneid
21: )
22:
23: $sip_from = "IC"
24: $time = [DateTime]::Now
25: $call_id = "${time}msgto${phoneid}"
26:
27: $message = @"28: NOTIFY sip:${phoneid}@${phoneip}:5060 SIP/2.029: Via: SIP/2.0/UDP ${serverip}30: From: <sip:${sip_from}@${serverip}>31: To: <sip:${phoneid}@${phoneip}>32: Event: check-sync33: Date: ${time}34: Call-ID: ${call_id}@${serverip}35: CSeq: 1300 NOTIFY36: Contact: <sip:${sip_from}@${serverip}>37: Content-Length: 038:39: "@
40:
41: $udpclient = New-Object System.Net.Sockets.UdpClient -argumentlist $phoneip,5060
42: $result = $udpclient.Send([System.Text.Encoding]::ASCII.GetBytes($message), $message.Length)
August 22nd, 2007 at 11:29 pm
A good script, but just a quick correction to part of your summary:
“Polycom phones respond to the “check-sync” event by re-comparing the config file last-modified date”
This used to be true in older versions of the Polycom software, but for the past couple of years the function has matured.
The Polycom phone will now read the first part of each file and do a comparison to see if the file has changed, rather than relying on the ‘modified date’.
August 22nd, 2007 at 11:29 pm
Great!
Some days ago I posted an example of how to use Powershell to send UDP Packets too… but to wake computers on the network, a the WakeOnLan technology.
http://viniciuscanto.blogspot.com/2007/01/wake-on-lan-powershell-acordando.html
Congratulations!
August 22nd, 2007 at 11:29 pm
Jeff - Yep, I’ll probably set our lab guy up with a text file of some sort containing all the info for our team phones, and then create a function that pipes the file into the script. Then he should just be able to say:
PS:1> .\Reboot-Phones
August 22nd, 2007 at 11:29 pm
So do you have a CSV or XML file of all the phones in your building that you can use to pipe the addresses into this script? Definitely a neat use of PowerShell.
August 22nd, 2007 at 11:29 pm
That is cool!
Jeffrey Snover [MSFT]
Windows PowerShell/MMC Architect
Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx