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)"
}
}