- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Where do you expect the name of the VM to be shown?
On screen?
In that file?
Not sure what exactly you are doing, you are running a script block on a Windows box from where you do an SSH to a Linux box.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi LucD,
I need to run from remote jump server to a Linux VM. I would like to get the output on screen and also get captured in text file.
In the output and in the text file, I am getting the hostname of windows jump server but I would like to get the Linux VM name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Shouldn't that line be
Write-Output "VMInfo by on $($date) for Linux Server : $($result.Output) `r`n" >> "D:\Date\output1.txt"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much LucD. that worked ![]()