Reply to Message

View discussion in a popup

Replying to:
ganapa2000
Hot Shot
Hot Shot

Unable to get the VM Name in the output

Hi,

I am unable to get the VM name from the invoke-sshcommand of a remote VM. Please help!!

$WPassword = "password123"
$pass = ConvertTo-SecureString -AsPlainText $WPassword -Force
$Creds = New-Object System.Management.Automation.PSCredential ("localhost\admin", $pass)
Invoke-Command -ComputerName WINJUMP01 -ScriptBlock {
$pass = ConvertTo-SecureString -AsPlainText "mypassword" -Force
$Cred = New-Object System.Management.Automation.PSCredential ("root", $pass)

$script = @"
echo "Checking VM Info of :: $(hostname)"
"@

$session = New-SSHSession -ComputerName "mylinuxvm" -Credential $Cred -AcceptKey
$result = Invoke-SSHCommand -SSHSession $session -Command $script -Verbose
Write-Output "VMInfo by on $($date) for Linux Server : $(hostname) `r`n" >> "D:\Date\output1.txt"
$result.output
Remove-SSHSession -SSHSession $session | Out-Null
} -credential $Creds

Reply
0 Kudos