VMware Cloud Community
EXPRESS
Enthusiast
Enthusiast
Jump to solution

Get-VM | Select Name,VMHost


Hi All,

I am looking for a way to get a list of all my VM's Tools Status but not from all the hosts in my Virtual Center 5.5. I have 6 hosts but only need information from 4 of them. I dont know how to exclude hosts so my report doesnt show VM's i dont want.

This is what I have which I have got from the community...

Get-VM | `

Select-Object -Property Name,@{N="State";E={$_.Guest.State}},@{N="ToolsStatus";E={$_.Guest.ExtensionData.ToolsStatus}}  | `

Where-Object {$_.ToolsStatus -eq "toolsNotRunning" -or $_.ToolsStatus -eq "toolsOld" -or $_.ToolsStatus -eq "toolsNotInstalled"}

it provides all the VM's in VC i would just like to include the ones from the hosts needed. I am not sure how to do that, i tried messing with Get-VMHost -Location, i have tried a few ways but nothing.

Thanks in advance.

Thank you, Express
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

One way of doing that would be to just name the 4 ESXi hosts like this

Get-VMHost -Name esx1,esx2,esx3,esx4 |
Get-VM |
Where-Object {$_.ToolsStatus -eq "toolsNotRunning" -or $_.ToolsStatus -eq "toolsOld" -or $_.ToolsStatus -eq "toolsNotInstalled"} |
Select-Object -Property Name,@{N="State";E={$_.Guest.State}},@{N="ToolsStatus";E={$_.Guest.ExtensionData.ToolsStatus}}


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

One way of doing that would be to just name the 4 ESXi hosts like this

Get-VMHost -Name esx1,esx2,esx3,esx4 |
Get-VM |
Where-Object {$_.ToolsStatus -eq "toolsNotRunning" -or $_.ToolsStatus -eq "toolsOld" -or $_.ToolsStatus -eq "toolsNotInstalled"} |
Select-Object -Property Name,@{N="State";E={$_.Guest.State}},@{N="ToolsStatus";E={$_.Guest.ExtensionData.ToolsStatus}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
EXPRESS
Enthusiast
Enthusiast
Jump to solution

LucD,

I still got the same results, :confused_face: All the VM's are still showing up. Is there a way to to an exclude of hosts?


Thank you, Express
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That seems very strange, can you try

Get-VMHost -Name esx1 | Get-VM

Does that return all VMs ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
EXPRESS
Enthusiast
Enthusiast
Jump to solution

LucD,

Yep, got it to work, thank you. Here it goes below incase anyone has any use for it as well, I have it set to email the report as well.

add-PSSnapin VMware.VimAutomation.Core | Out-Null

connect-viserver VC55.mycomp.com -User admin -Pass P@$$w0rD

Get-VMHost -Name esx1, esx2, esx3 | Get-VM | Select-Object -Property Name ,@{N="State";E={$_.Guest.State}},@{N="ToolsStatus";E={$_.Guest.ExtensionData.ToolsStatus}} | Where-Object {$_.ToolsStatus -eq "toolsNotRunning" -or $_.ToolsStatus -eq "toolsOld" -or $_.ToolsStatus -eq "toolsNotInstalled"} | Format-Table -AutoSize | Out-File "C:\Logs\Status_$((get-date).toString('MM-dd-yyyy_hh.mmtt')).log"

$logsFile = Resolve-Path "C:\Logs\*.log"

$SmtpServer = "smtp.mycomp.com"
$EmailFrom = "ToolsStatus@mycomp.com"
$EmailTo = "Me<Me@mycomp.com>"
$Body = Get-VMHost -Name esx1, esx2, esx3, | Get-VM | Select-Object -Property Name ,@{N="State";E={$_.Guest.State}},@{N="ToolsStatus";E={$_.Guest.ExtensionData.ToolsStatus}} | Where-Object {$_.ToolsStatus -eq "toolsNotRunning" -or $_.ToolsStatus -eq "toolsOld" -or $_.ToolsStatus -eq "toolsNotInstalled"} | ConvertTo-Html
$Body += "<br> </br>"
$Body += "Listed Servers should be updated or checked."
$Subject = "Status_$((get-date).toString('MM-dd-yyyy_hh:mmtt'))"
$mailer = new-object Net.Mail.SMTPclient($SmtpServer)
$msg = new-object Net.Mail.MailMessage($EmailFrom,$EmailTo,$Subject,$Body)
$msg.IsBodyHTML = $true
$mailer.send($msg)

Thank you,

Thank you, Express
Reply
0 Kudos