I am trying to write a script which will do the following :
Find only Windows VMs with a tool status of OLD and then upgrade the VM.
So far I have been able to update all VMs in a particular folder and I've found some information on how to create a list based upon Guest.ToolStatus and Guest.GuestFamily but I would prefer to not export/import a list to perform these upgrades by DC and by Folder.
Thank you in advance for any assistance.
Try this
<pre><span style="color: #5F9EA0; font-weight: bold;">Get-VM</span><span style="color: #000000;"> | </span><span style="color: #5F9EA0; font-weight: bold;">where</span><span style="color: #000000;"> { </span><span style="color: #800080;">$_</span><span style="color: #000000;">.guest.GuestFamily </span><span style="color: #FF0000;">-match</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">Windows</span><span style="color: #800000;">"</span><span style="color: #000000;"> </span><span style="color: #FF0000;">-and</span><span style="color: #000000;"> </span><span style="color: #800080;">$_</span><span style="color: #000000;">.ExtensionData.Guest.ToolsStatus </span><span style="color: #FF0000;">-eq</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">ToolsOld</span><span style="color: #800000;">"</span><span style="color: #000000;"> } | </span><span style="color: #5F9EA0; font-weight: bold;">foreach</span><span style="color: #000000;"> { </span><span style="color: #5F9EA0; font-weight: bold;">Update-Tools</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-VM</span><span style="color: #000000;"> </span><span style="color: #800080;">$_</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-NoReboot</span><span style="color: #000000;"> }</span></pre>
Message was edited by: DZ1
Sorry...try this:
Get-VM | where { $_.guest.GuestFamily -match "Windows" -and $_.ExtensionData.Guest.ToolsStatus -eq "ToolsOld" } | foreach { Update-Tools -VM $_ -NoReboot }