Skip to content

Restart Polycom X50/X30

Updated: at 08:30 PM

This script is designed to restart Polycom X50 or X30 with Powershell, Featuring call functions via Polycoms published Rest API

This was community sourced with alterations to fit my environment and ammending it to be able to send email notifications.

Scenario #1

With meeting rooms being deployed throughout offices in the country, we found the maintenance overheads frustrating and required L1 Technicians to be attending the meeting rooms frequently.

NOTE: Polycom now natively supports restart schedules! If you’re after email confirmations in any form, this script can still apply.

PowerShell Script

If you’re new to scripting, looking at this will be intimidating (heck it still is!) and look complicated. There are definitely flaws in the script- such as having plain-text administrator credentials being stored, for our environment this is not an issue and we use a randomised password for the equipment.

Initially, we set up variables for the IP addresses of the X50/X30 and the password utilized for logging in as the admin account.

$polycoms = "192.168.0.5","192.168.0.10"
$password = "xxxxxxxxxx"

Following that, we establish a Try {} ForEach loop and specify the URLs for sessions along with the session body, encapsulating the credentials to be executed by the REST API. While we have stored the password in a variable, the username within our environment remains as “admin,” defined in the “user:” field as outlined below.

Try {

    ForEach ($polycom In $polycoms){


    #URL to make new session
    $sessionURL = ("https://" + $polycom + "/rest/session");
    #Command to make new session
    $sessionBody = "{`"user`": `"admin`",`"password`": `"" + $password + "`"}"

    #URL to issue reboot
    $rebootURL = ("https://" + $polycom + "/rest/system/reboot");
    #Command to issue reboot
    $rebootBody = "{`"action`": `"reboot`"}"

We then need to disable the self-signed certificate checking. After this section of the script, the script will run process each $polycom, creating a session and invoking a web-request via the REST API to trigger the restarts.

# disable self signed certificate check
    if (-not ([System.Management.Automation.PSTypeName]'ServerCertificateValidationCallback').Type)
    {
    $certCallback = @"
    using System;
    using System.Net;
    using System.Net.Security;
    using System.Security.Cryptography.X509Certificates;
    public class ServerCertificateValidationCallback
    {
        public static void Ignore()
        {
            if(ServicePointManager.ServerCertificateValidationCallback ==null)
            {
                ServicePointManager.ServerCertificateValidationCallback += 
                    delegate
                    (
                        Object obj, 
                        X509Certificate certificate, 
                        X509Chain chain, 
                        SslPolicyErrors errors
                    )
                    {
                        return true;
                    };
            }
        }
    }
"@
    Add-Type $certCallback

    }
    [ServerCertificateValidationCallback]::Ignore()
    # End self signed certificate commands

    Invoke-WebRequest $sessionURL -ContentType "application/json" -Method Post -body $sessionBody -SessionVariable sess;
    Invoke-WebRequest $rebootURL -ContentType "application/json" -Method Post -WebSession $sess -Body $rebootBody

The following section in the script deals with email notifications, configured through M365 SMTP relay. The configuration for this phase will vary significantly depending on your environment. While this portion of the script could use some TLC in a form of refinement and modernization, it currently functions without causing any issues for us.

The initial step involves setting up credentials. These credentials should belong to a user or mailbox, potentially an admin (although not recommended!) or a service account designated for automation purposes. When you execute this command in your PowerShell session, a dialogue box will emerge, prompting you to log in. Subsequently, your password will be securely stored in an encrypted format at the specified location.

(get-credential).password | ConvertFrom-SecureString | set-content "C:\Scripts\Encrypted.txt"

Once you’ve executed that, I would recommend commenting that line out to avoid the complete script from failing when ran. Then, we define the credentials and encrypted password with the below variables:

$username = "[email protected]"
$userpassword = Get-Content "C:\Scripts\Encrypted.txt" | ConvertTo-SecureString
$credential = New-Object System.Management.Automation.PsCredential ($username, $userpassword)

Following that, we proceed with configuring the SMTP user, sending address, subjects, and body. In the event of script failure, it will be captured within the Catch {} segment and appended to a log file located at the specified path.

#email settings via SMTP
$User = "contoso.com"
$SMTP = "smtp.office365.com"
$To = "[email protected]"
$Subject1 = "ROOM: Conference equipment has FAILED to restart"
$Body1 = "Scripts have failed on ScheduledDay:ScheduledTime, please check SERVERNAME C:\Scripts\RestartPolycomConference.txt for the error logs"
$Subject2 = "ROOM: Conference equipment restart SUCCESS"
$Body2 = "The Following Polycom Conference equipment has been successfully restarted:
$Polycoms"
$Creds = (Get-Credential $credential)

Send-MailMessage -To $To -From $User -Subject $Subject2 -Body $Body2 -SmtpServer $SMTP -Credential $Creds -UseSsl

} 
}Catch {

Send-MailMessage -To $To -From $User -Subject $Subject1 -Body $Body1 -SmtpServer $SMTP -Credential $Creds -UseSsl
Get-Date -Format "dddd MM/dd/yyyy HH:mm" | Out-File -FilePath "C:\Scripts\RestartPolycomConference.txt" -Append
$error | Out-File -FilePath "C:\Scripts\RestartPolycomConference.txt" -Append

}

Below is the complete script

$polycoms = "192.168.0.5","192.168.0.10"
$password = "xxxxxxxxxx"
    
Try {

    ForEach ($polycom In $polycoms){


    #URL to make new session
    $sessionURL = ("https://" + $polycom + "/rest/session");
    #Command to make new session
    $sessionBody = "{`"user`": `"admin`",`"password`": `"" + $password + "`"}"

    #URL to issue reboot
    $rebootURL = ("https://" + $polycom + "/rest/system/reboot");
    #Command to issue reboot
    $rebootBody = "{`"action`": `"reboot`"}"


    # disable self signed certificate check
    if (-not ([System.Management.Automation.PSTypeName]'ServerCertificateValidationCallback').Type)
    {
    $certCallback = @"
    using System;
    using System.Net;
    using System.Net.Security;
    using System.Security.Cryptography.X509Certificates;
    public class ServerCertificateValidationCallback
    {
        public static void Ignore()
        {
            if(ServicePointManager.ServerCertificateValidationCallback ==null)
            {
                ServicePointManager.ServerCertificateValidationCallback += 
                    delegate
                    (
                        Object obj, 
                        X509Certificate certificate, 
                        X509Chain chain, 
                        SslPolicyErrors errors
                    )
                    {
                        return true;
                    };
            }
        }
    }
"@
    Add-Type $certCallback

    }
    [ServerCertificateValidationCallback]::Ignore()
    # End self signed certificate commands

    Invoke-WebRequest $sessionURL -ContentType "application/json" -Method Post -body $sessionBody -SessionVariable sess;
    Invoke-WebRequest $rebootURL -ContentType "application/json" -Method Post -WebSession $sess -Body $rebootBody
    

# SENDING AN EMAIL NOTIFICATION
# Below line needs to be ran once to produce the encrypted test.txt file
#(get-credential).password | ConvertFrom-SecureString | set-content "C:\Scripts\Encrypted.txt"
$username = "[email protected]"
$userpassword = Get-Content "C:\Scripts\Encrypted.txt" | ConvertTo-SecureString
$credential = New-Object System.Management.Automation.PsCredential ($username, $userpassword)

#email settings via SMTP
$User = "contoso.com"
$SMTP = "smtp.office365.com"
$To = "[email protected]"
$Subject1 = "ROOM: Conference equipment has FAILED to restart"
$Body1 = "Scripts have failed on ScheduledDay:ScheduledTime, please check SERVERNAME C:\Scripts\RestartPolycomConference.txt for the error logs"
$Subject2 = "ROOM: Conference equipment restart SUCCESS"
$Body2 = "The Following Polycom Conference equipment has been successfully restarted:
$Polycoms"
$Creds = (Get-Credential $credential)

Send-MailMessage -To $To -From $User -Subject $Subject2 -Body $Body2 -SmtpServer $SMTP -Credential $Creds -UseSsl

} 
}Catch {

Send-MailMessage -To $To -From $User -Subject $Subject1 -Body $Body1 -SmtpServer $SMTP -Credential $Creds -UseSsl
Get-Date -Format "dddd MM/dd/yyyy HH:mm" | Out-File -FilePath "C:\Scripts\RestartPolycomConference.txt" -Append
$error | Out-File -FilePath "C:\Scripts\RestartPolycomConference.txt" -Append

}

✨ Feedback & Suggestions

If you have any suggestions/feedback, you can contact me via my email.