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..
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
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
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..
Try:
where {$_.Guest.ToolsStatus -ne "toolsOk" -and $_.Guest.ToolsStatus -ne "toolsOld"}
Of course there are easier and nicer ways of doing this
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
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
That was again a home run Luc
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
VMSavvy..
That would be
Get-View -ViewType HostSystem
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference