SSH through Powershell

So recently doing a deployment of Polycom Clariti One Touch Dial, I needed to make sure that the Tandberg rooms where getting the update information form OTD.  The trick to checking this out to SSH to the device and then run a command.  But first you need to make sure that you have also set the permissions on the mailbox too.  You can do this easily with this script Setting mailbox Folder Permissions in Any Language  So first you need to install the Posh-SSH PowerShell.  You should be able to do that by simply by running Install-Module Posh-SSH  If you cannot do that, check out this article first Better ways to install Powershell stuff .

Then you can run this command .

Notice the sleep, I ended up needing to put that in there because if I did not, for whatever reason the read() statement was empty

In this example I have a list of all the rooms in the text file roomlist.txt with the FQDN of the Tandberg system.  I send that out to a text file, then search the text file for the title string and then see if my test meeting shows up.

$searchstring = 'title: '
foreach ($room in get-content C:\logs\roomlist.txt) {
$newssh = $null
$tempstring = $null
$tempfile = $null
$ssh = $null
$tempfile = [System.IO.Path]::GetTempFileName()

$ssh = New-SSHSession -ComputerName $room -Credential $cred -Port 22 -AcceptKey
$newssh = New-SSHShellStream -SessionId $ssh.SessionId

$newssh.WriteLine("xcommand bookings list")
Start-Sleep -Milliseconds 500
$newssh.read() | out-file $tempfile

$lines = get-content $tempfile | Select-String -Pattern $searchstring | select Line 

$string =$room+","+$lines

out-file c:\logs\odtrooms.txt -InputObject $string -Append