Microsoft Virtualization Discussions

Can you use Posh-SSH PowerShell Module for administering OnTap?

Jim_Robertson
2,367 Views

In the past, I've used Invoke-NcSSH to administer Ontap clusters from a central location.  i.e. I could pull the aggregate list from a cluster using a command like this:

Invoke-NcSSH -Controller ClusterName -Command "aggr show"

I also created a function to make the command shorter and allow me to run any OnTap CLI command on any cluster from a PowerShell window.  The problem is that it requires Putty >0.70 to be installed (no big deal), but it's really really slow.

I thought that Posh-SSH might work better, but you first have to establish a session, find the session ID, invoke a session to that session ID, then parse the output to get the data that I need.  This is what a Posh-SSH session looks like to do the same as what I'm doing with Invoke-NcSSH:

New-SSHSession -ComputerName ClusterName
Get-SSHSession
$var = Invoke-SSHCommand -SessionId 0 -Command "aggr show"
$var.Output

Does anyone have any fancy ways to make Posh-SSH work more like the way I was using Invoke-NcSSH above?  Essentially, I'd like to be able to run an OnTap CLI command from PowerShell using a single PS command.

Thanks in advance for any hints anyone can give me!

1 REPLY 1

Ashun
122 Views

hi guys

You mean, you want to use Posh-SSH to send commands to the cluster one by one, like the CLI?

Seems a bit unnecessary, why not use powershell to connect directly to ssh admin@x.x.x.x instead of posh-SSH? I did it a little bit the way you wanted, and you can try it like that, but he seemed kind of funny, like he took his pants off and farted

With this in mind, you should first know that you need to install Posh-SSH module, and then you need to be very familiar with ontap command, because it can't Tab complete commands like in CLI, so you have to type all the commands yourself.


script


$ONTAPHost = Read-Host "Enter the IP address of the ONTAP cluster"
$User = Read-Host "login"
$Password = Read-Host "password" -AsSecureString

Import-Module Posh-SSH
$credential = New-Object System.Management.Automation.PSCredential($User, $Password)

try {
$session = New-SSHSession -ComputerName $ONTAPHost -Credential $credential -ErrorAction Stop
Write-Host "SSH session established successfully."
} catch {
Write-Host "Failed to create SSH session. Error: $($_.Exception.Message)"
exit
}

while ($true) {
$command = Read-Host "Enter command (Type 'exit' to exit)"

if ($command -eq 'exit') {
Remove-SSHSession -SessionId $session.SessionId
Write-Host "SSH session closed."
break
}

try {
$result = Invoke-SSHCommand -SessionId $session.SessionId -Command $command
$result.output
} catch {
Write-Host "Failed to execute command. Error: $($_.Exception.Message)"
}
}

Public