-
1. Re: How to check VMware Tools status of VM use PowerCLI
ThompsG Apr 28, 2019 10:53 PM (in response to as900w)Hi as900w,
Try the following (all standard disclaimers and warranty excemptions apply):
# Creates a variable that contains VMs which are in the PoweredOn state
$VMList = Get-VM | Where { $_.PowerState -eq "PoweredOn" }
# Loops through the variable an object at a time
Foreach ( $VM in $VMList ) {
# Retrieve the status of the VMware Tools
$ToolsStatus = ($VM | Get-View).Guest.ToolsStatus
# Check status of tools and if not installed then issue Stop to VM otherwise Shutdown VM
If ( $ToolsStatus -eq "toolsNotInstalled" ) {
Stop-VMGuest $VM
} Else {
Shutdown-VMGuest $VM
}
}
NOTE: Test to confirm it does as you expect before unleashing in production
Kind regards.
-
2. Re: How to check VMware Tools status of VM use PowerCLI
as900w Apr 29, 2019 7:23 PM (in response to ThompsG)Thanks for your help.
it's OK.
If I want to exclude some VM in the list.
What should I do?
-
3. Re: How to check VMware Tools status of VM use PowerCLI
ThompsG Apr 29, 2019 9:12 PM (in response to as900w)Hi there,
Perhaps try something like this:
# Creates a variable that contains VMs which are in the PoweredOn state
$VMList = Get-VM | Where { $_.PowerState -eq "PoweredOn" }
# Names of VMs that will not be shutdown or powered off
$VMExclusionList = "vm1","vm2","vm3"
# Loops through the variable an object at a time
Foreach ( $VM in $VMList ) {
# Checks if the name of the current VM is in the ExclusionList and skips if it is
If ( $VMExclusionList -notcontains $VM.Name ) {
# Retrieve the status of the VMware Tools
$ToolsStatus = ($VM | Get-View).Guest.ToolsStatus
# Check status of tools and if not installed then issue Stop to VM otherwise Shutdown VM
If ( $ToolsStatus -eq "toolsNotInstalled" ) {
Stop-VM $VM
} Else {
Shutdown-VMGuest $VM
}
}
}
Just update the $VMExclusionList variable with names of the VMs you don't want to shutdown or poweroff.
Kind regards.
-
4. Re: How to check VMware Tools status of VM use PowerCLI
as900w Apr 29, 2019 9:20 PM (in response to ThompsG)It's OK.
Thanks a lot!
-
5. Re: How to check VMware Tools status of VM use PowerCLI
as900w Apr 30, 2019 12:02 AM (in response to ThompsG)The -Confirm:$False is added after stop-vm command.
But it's failed.
-
6. Re: How to check VMware Tools status of VM use PowerCLI
ThompsG Apr 30, 2019 4:12 AM (in response to as900w)Was this for all VMs that don’t have the tools or just a couple?
-
7. Re: How to check VMware Tools status of VM use PowerCLI
as900w May 6, 2019 6:18 PM (in response to ThompsG)this tools is for all vm
-
8. Re: How to check VMware Tools status of VM use PowerCLI
ThompsG May 6, 2019 9:43 PM (in response to as900w)