Skip to content

Instantly share code, notes, and snippets.

@ruddj
Last active October 26, 2020 03:39
Show Gist options
  • Save ruddj/d5bfbcb5c3744edc05c9632ce74c4f85 to your computer and use it in GitHub Desktop.
Save ruddj/d5bfbcb5c3744edc05c9632ce74c4f85 to your computer and use it in GitHub Desktop.
Update-PhoneSIP
<#
.SYNOPSIS
Bulk update NEC ITK Phones saved SIP user-id and Password
.DESCRIPTION
Will update the saved UserID, Password and Extension on an NEC ITK series phone with the Ext numbr it is registered to an SV9100 system with
Requries a CSV export from PCPro SV9100 of 15-05. This contains the Extension to IP address mapping.
Assumes the SIP userid and Password is the same for all extensions
Only tested on SV9100 AU and ITK-24CG phone. Strongly suggest testing on a single extension before bulk updating
.EXAMPLE
In SV9100 PCPro -> Reports System data
Tick 15-05 -> Export as CSV
Update phone username and password below and the SIP account password
.NOTES
Author: James Rudd
Blog : http://jrudd.org/
#>
# Phone Login
$User = "ADMIN"
$Password = "<Pass>"
# Export 15-05 Phones List as CSV
$CSVfile = "C:\Temp\15-XX(3).csv"
# Account Pass
$SipPassword = "123456789"
$IpPhoneList = Import-csv $CSVfile -Header Extension,Type,MAC,Nickname,IPAddress |Select-Object -Skip 1
# Log Errors
$phoneErrors = New-Object System.Collections.Generic.List[System.Object]
# Loop over Phones
foreach ($phone in $IpPhoneList){
$SipExt = $phone.Extension
if($SipExt -notmatch "\d{3}"){
Write-Host "Not a valid Extension ${SipExt} " -ForegroundColor Red
$phoneErrors.Add("${SipExt}: Not a valid Extension")
continue
}
$PhoneIP = $phone.IPAddress
$phoneBase = "http://$PhoneIP"
if($phone.Type -notlike "DT900*"){
Write-Host "Extension ${SipExt} is not a DT Phone $PhoneIP" -ForegroundColor Yellow
$phoneErrors.Add("${SipExt}: Not a DT Phone")
continue
}
# Test Ping phone to check up
if (-not (Test-Connection -ComputerName $PhoneIP -Quiet)){
Write-Host "Extension ${SipExt} could not ping $PhoneIP" -ForegroundColor Red
$phoneErrors.Add("${SipExt}: Could not ping $PhoneIP")
continue
}
# Login to Phone (this will lock the phone)
#Referer: http://IP/index.cgi?login=0\r\n
$URL = "${phoneBase}/index.cgi?username=${User}&password=${Password}"
$R = Invoke-WebRequest -Uri $URL -SessionVariable necPhone -Method GET
# Get Session ID
#<frame src="./menu.cgi?session=2c4a" name="left" >
if ($R.Content -match 'index\.cgi\?session=([\d\w]+)'){
$sessionID=$Matches[1]
} else {
Write-Host "Unable to get session ID for $SipExt on $PhoneIP" -ForegroundColor Red
$phoneErrors.Add("${SipExt}: No Session ID")
continue
}
# Set UserID
#http://IP/index.cgi?session=2c4a&set=40a0418&item=359
$URL = "${phoneBase}/index.cgi?session=$sessionID&set=40a0418&item=${SipExt}"
$R = Invoke-WebRequest -Uri $URL -WebSession $necPhone
# Set Password
# /index.cgi?session=2c4a&set=40a0583&item=1234
$URL = "${phoneBase}/index.cgi?session=$sessionID&set=40a0583&item=${SipPassword}"
$R = Invoke-WebRequest -Uri $URL -WebSession $necPhone
# Set Extension
# http://IP/index.cgi?session=2c4a&set=40a041a&item=359
$URL = "${phoneBase}/index.cgi?session=$sessionID&set=40a041a&item=${SipExt}"
$R = Invoke-WebRequest -Uri $URL -WebSession $necPhone
# Save and Reboot
#http://IP/index.cgi?session=2c4a&set=all
$URL = "${phoneBase}/index.cgi?session=$sessionID&set=all"
$R = Invoke-WebRequest -Uri $URL -WebSession $necPhone
Write-Host "Updated Extension $SipExt on $PhoneIP" -ForegroundColor Green
}
$Errors = $phoneErrors -join "`r`n"
Write-Host "Failed Extensions:`r`n$Errors" -ForegroundColor Red
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment