Hi! I’m developing a Dashboard that has a function to connect to a Linux SSH Session to reboot an IPPhone. I’m using SSHSession Module from here: https://www.powershelladmin.com/wiki/SSH_from_PowerShell_using_the_SSH.NET_library
So, I use encrypted credentials to connec to the PBX as this:
$PasswordFile_PBX = “C:\UDService\Password_PBX.txt”
$key_PBXFile_PBX = “C:\UDService\AES_PBX.key”
$User_PBX = “root”
$key_PBX = Get-Content $key_PBXFile_PBX
$Cache:Credential_PBX = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User_PBX, (Get-Content $PasswordFile_PBX | ConvertTo-SecureString -Key $key_PBX)
The Function:
Function ResetIPPhone {
param ($extension,$pbx)
New-SshSession -ComputerName $pbx -Credential $Cache:Credential_PBX
$command = “asterisk -rx ‘sip notify polycom-check-cfg $extension’”
Invoke-SshCommand -ComputerName $pbx -command $command
Remove-SshSession -ComputerName $pbx
}
UD portion:
New-UDInput -Title "Reboot IP Phone" -SubmitText "Reboot" -Content {
New-UDInputField -Type 'textbox' -Name 'Extension'
}-Endpoint {
param($Extension)
ResetIPPhone -Extension $Extension -pbx IP_OF_PBX
Show-UDToast -Message "Rebooting Phone..."
}
So, It does work perfect when I ran it, but then, if someone else runs it AFTER me (other extension for example), He gets the message “The Variable ‘Global:SshSessions’ cannot be retreived because it has not been set’”.
If I restart the UD Service, and then, that person tries to run reboot, it DOES work, but if I try, the error appears.
Any help with be appreciated.