VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

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
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Thank you very much LucD. that worked :slightly_smiling_face:

Reply
0 Kudos