Finding vms with vmware tools that need to be upgraded. vmware tools status and version

Right, this is not some rocket science here but still i thought some people may be looking for that.

get-cluster your_cluster |Get-VM|?{$_.Extensiondata.Summary.Guest.ToolsVersionStatus -like 'guestToolsNeedUpgrade'} | select name,@{N='tools vers';E={$_.ExtensionData.Config.Tools.ToolsVersion}},@{N='Tools Status';E={$_.Extensiondata.Summary.Guest.ToolsVersionStatus}}

So i wanted to take cluster ‘your_cluster’ and get all vms in this cluster that have tools status of ‘guestToolsNeedUpgrade’. Well basically that’s pretty much it but i noticed that on large inventory it takes quite time to receive this list. So what might be interesting for people who have bigger vInfrastructure 😉
This query takes
Seconds : 41
So i spend few more minutes to get the same list but using get-view. It took:
Seconds : 1
Milliseconds : 174

And the line:

get-view -ViewType virtualmachine -SearchRoot (get-cluster your_cluster).id -Filter @{'Summary.Guest.ToolsVersionStatus'='guestToolsNeedUpgrade'} | Select Name,@{N='tools ver';E={$_.Config.Tools.ToolsVersion}},@{N='Tools Status';E={$_.Summary.Guest.ToolsVersionStatus}}

So difference is 40 seconds 😉 Output is formatted like this
Name tools ver Tools Status
—- ———- ————
myvm1 8300 guestToolsNeedUpgrade
myvm2 8300 guestToolsNeedUpgrade
…… ….. ……………..

how to check which vms have snapshots in a very dirty but quick way?

I have written more advanced scripts for printing, reporting stuff about snapshots than this one, but here it is just about to see which vm has snapshot. That is all i want by running this command. And i want to see the results FAST!, i mean NOW!, or like YESTERDAY! 😉

Get-View -ViewType VirtualMachine -Filter @{"snapshot" = ""} | select name

That’s it ;], nothing more. It will just output the vSphere .net view object for vms that have snapshots on it. Once again, it is not fancy, it does not send e-mail, it does not do coffee while running, it just shows you vms with snapshots on it. You can build your own “EXTRA” around this if you want. I just wanted to see very quickly if i have snaps or not. If you have any better idea / quicker how to view snapshots on vm, please post a comment!

Function for getting report on annotation in VirtualCenter server clusters or particular cluster

I described one way of getting this report in earlier post. If you want to use it as a function… there you go 😉
You can always use get-help greg-get-annotations , if you are in powershell session and want to check the syntax etc..
Report will also include the normal notes section. I’ve tested it in some environments, for example it took 38 sec to complete it in VI where there was ~1500vms, including creation of the csv.

function greg-get-annotations {
Greg-get-annotations function stores information about annotation fields for vms in given
cluster or in all clusters in VC. It stores the result in an arraylist $vms, you can either create
a csv report from this object or display it on screen
greg-get-annotations |export-csv -NoTypeInformation c:\file1.csv will export it to csv file etc...
greg-get-annotations |format-table VMname,Cluster,CreatedOn,Notes will just display on screen a table with
annotations that include : vm name, its cluster and field "CreatedOn" and Notes

.PARAMETER clustername
Specifies the clustername against wchi report will be built

greg-get-annotations -clustername 'cluster01'|Export-Csv c:\annotation-report.csv
Will procude report on vms that resides in 'cluster01' and store it in csv file

greg-get-annotations -clustername 'cluster01'|ft *
Will procude report on vms that resides in 'cluster01' output it to screen

greg-get-annotations |Export-Csv c:\annotation-report.csv
Will procude report on vms that resides in all clusters and output it to screen

Without specified -clustername switch, it will do report regarding all clusters in VC

AUTHOR: Grzegorz Kulikowski
LASTEDIT: 05/30/2011

param ([string]$clustername)
if(!($clustername)){$clusters=Get-Cluster}else{$clusters=Get-Cluster $clustername}
$VMs=New-Object Collections.ArrayList
foreach ($cluster in $clusters)  {
foreach ($vmview in (get-view -ViewType VirtualMachine -SearchRoot $ {
$vm=New-Object PsObject
Add-Member -InputObject $vm -MemberType NoteProperty -Name VMname -Value $vmview.Name
Add-Member -InputObject $vm -MemberType NoteProperty -Name Notes -Value $vmview.Config.Annotation
Add-Member -InputObject $vm -MemberType NoteProperty -Name Cluster -Value $cluster.Name
foreach ($CustomAttribute in $vmview.AvailableField){
Add-Member -InputObject $vm -MemberType NoteProperty -Name $CustomAttribute.Name -Value ($vmview.Summary.CustomValue | ? {$_.Key -eq $CustomAttribute.Key}).value
return $VMs

Add-Member -InputObject $vm -MemberType NoteProperty -Name Notes -Value $vmview.Config.Annotation

Change the syslog server for esxi5 box using powercli

Let’s say that we would like to change the syslog server to which our esxi5 boxes is sending logs in some particular cluster.

$changedValue = New-Object VMware.Vim.OptionValue[] (1)
$changedValue[0] = New-Object VMware.Vim.OptionValue
 $changedValue[0].key = ""
 $changedValue[0].value = "tcp:/your-syslog-ip:514"

Get-View -ViewType HostSystem -Searchroot (Get-Cluster "your-cluster-name").Id | %{
  $optMgr = Get-View $_.ConfigManager.AdvancedOption

Now check if we have updated values

get-view -viewtype HostSystem -SearchRoot (get-cluster "our-cluster").id | % { get-view $_.ConfigManager.AdvancedOption | select -ExpandProperty Setting |?{$_.Key -like ""} }

Many thanks to LucD for pointing me out a better way to go with updating this value!

Check vm vmnic vlan

I wanted to get a list of vms that are using specific vlan so i wrote this one:

foreach($vm in (get-vm)){
if (Get-NetworkAdapter -vm $ |?{$_.NetworkName -eq "network23" -or $_.NetworkName -eq "network65"}){$}

Ok, that was working but it was VERY VERY VERY VERY VERY slow…

So i wrote it using get-view :

$vms=get-view -viewtype virtualmachine
foreach($vmview in $vms )
$ntwkview=get-view -id $
foreach($ntwkentry in $ntwkview){
if ($ -eq "network23" -or $ -eq "network65")

This one needed only 3 minutes to complete on a ~1000vm infrastructure. I stop the first script after 30minutes of running as it would probably finish next day …

The script is not perfect… yet 😉 but it will do the job and what’s most important quickly. I hope this will save you some time on reporting.