VMware Cloud Community
VMSavvy
Enthusiast
Enthusiast
Jump to solution

Script to pull out VM Tools "Not Running and Not Installed"

Hi all,

I'm using a script to pull out VMs in which VM tools is not installed or not running.. I'm using the following code. It pulls out all the list including toolsok and toolsold..and also has some blank fields in the output.

I'm sure there's a bug in my where statement down there..Pls help!!

get-vm | ForEach-Object {
  $vm = Get-View $_.ID | where {$_.guest.toolsstatus -ne "toolsOk" -or "toolsOld"}
    $vms = "" | Select-Object VMName, VMState, ToolsStatus, ToolsVersion
    $vms.VMName = $vm.Name
    $vms.VMState = $vm.summary.runtime.powerState
    $vms.ToolsStatus = $vm.guest.toolsstatus
    $vms.ToolsVersion = $vm.config.tools.toolsversion
    $Report += $vms
    }
$Report | ConvertTo-Html -title "VMware Tools Out of Date, Not Installed and Not Running" -body "<H2>VMware Tools Out of Date, Not Installed and Not Running</H2>" | Out-File -Append $filelocation

Output screenshot is attached..

Thanks,

VMSavvy..

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Your original script becomes

$report = @()
$fileLocation = "C:\test.html"

Get-View
-ViewType VirtualMachine | where {"toolsNotInstalled","toolsNotRunning" -contains $_.Guest.ToolsStatus} | %{     $vms = "" | Select-Object VMName, VMState, ToolsStatus, ToolsVersion
    $vms.VMName = $_.Name     $vms.VMState = $_.summary.runtime.powerState     $vms.ToolsStatus = $_.guest.toolsstatus     $vms.ToolsVersion = $_.config.tools.toolsversion     $Report += $vms
}
$Report | `
ConvertTo-Html -title "VMware Tools Out of Date, Not Installed and Not Running" -body "<H2>VMware Tools Out of Date, Not Installed and Not Running</H2>" | `
Out-File -Append $filelocation Note that the script only uses the Get-View cmdlet, this will make it considerably faster than your original version.


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

View solution in original post

0 Kudos
7 Replies
RR9
Enthusiast
Enthusiast
Jump to solution

Check this post http://communities.vmware.com/message/1500223

You can also try this

Get-Cluster nameofTheCluster | Get-VM | Sort Name | Select Name,PowerState,Notes,VMHost

VMSavvy
Enthusiast
Enthusiast
Jump to solution

That helps but I'm looking to sort out only the ones which are not installed and not running tools.. I messed up something in the where statement..

0 Kudos
alanrenouf
VMware Employee
VMware Employee
Jump to solution

Try:

where {$_.Guest.ToolsStatus -ne "toolsOk" -and $_.Guest.ToolsStatus -ne "toolsOld"}

Of course there are easier and nicer ways of doing this Smiley Wink

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
0 Kudos
LucD
Leadership
Leadership
Jump to solution

To get the guests with no tools installed use this where-clause

where {"toolsNotInstalled" -eq $_.Guest.ToolsStatus}

If you also like to find the ones that have the tools but where they are not running, you can do

where {"toolsNotInstalled","toolsNotRunning" -contains $_.Guest.ToolsStatus}

You can find all possible values in the definition of the VirtualMachineToolsStatus enumeration.


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

LucD
Leadership
Leadership
Jump to solution

Your original script becomes

$report = @()
$fileLocation = "C:\test.html"

Get-View
-ViewType VirtualMachine | where {"toolsNotInstalled","toolsNotRunning" -contains $_.Guest.ToolsStatus} | %{     $vms = "" | Select-Object VMName, VMState, ToolsStatus, ToolsVersion
    $vms.VMName = $_.Name     $vms.VMState = $_.summary.runtime.powerState     $vms.ToolsStatus = $_.guest.toolsstatus     $vms.ToolsVersion = $_.config.tools.toolsversion     $Report += $vms
}
$Report | `
ConvertTo-Html -title "VMware Tools Out of Date, Not Installed and Not Running" -body "<H2>VMware Tools Out of Date, Not Installed and Not Running</H2>" | `
Out-File -Append $filelocation Note that the script only uses the Get-View cmdlet, this will make it considerably faster than your original version.


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

0 Kudos
VMSavvy
Enthusiast
Enthusiast
Jump to solution

That was again a home run Luc Smiley Happy

and the get-view cmdlet is just amazing.. it took atleast 10mins before for me.. but now it takes not even a minute..

like Get-View -Type VirtualMachine can I use Get-View -Type Host for ESX host? this makes my host maintenance script run like a rocket Smiley Happy

VMSavvy..

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That would be

Get-View -ViewType HostSystem


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

0 Kudos