I've been looking through the forums for several hours but I haven't been able to find any scripts that specifically list Windows 10 VMs with the OS Build version ie: 21H2, or 19044.1889. Either would be fine. I wasn't even able to find the powercli property for this specific information. Any help would be appreciated.
You could do something like this.
Note1: this will only work for VMs that are powered on and have the VMware Tools installed.
Note2: the Invoke-VMScript might require a GuestCredential parameter when the account that runs the script is not allowed to loon to the Guest OS
Note3: you might need to add additional cases to the switch statement
$code = @'
Switch ($((get-ciminstance Win32_OperatingSystem).buildnumber))
{
17763 {'Windows 10 - 1809'}
18362 {'Windows 10 - 1903'}
18363 {'Windows 10 - 1909'}
19041 {'Windows 10 - 2004'}
19042 {'Windows 10 - 29H2'}
19043 {'Windows 10 - 21H1'}
19044 {'Windows 10 - 21H2'}
22000 {'Windows 11'}
Default {'unable to determine the release off of the build number ' }
}
'@
Get-VM | where{$_.Guest.OSFullName -match '^Microsoft Windows 10' -and $_.PowerState -eq 'PoweredOn'} |
ForEach-Object -Process {
$result = Invoke-VMScript -VM $_ -ScriptText $code -ScriptType Powershell -
if($result.ScriptOutput -match '21H2'){
$_.Name
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you for this. It started running through them, but stopped as soon as it hit a machine my credentials didn't have access to. I would probably have to invoke a guest credential for the other servers, but we have hundreds of unique credentials per server. I was hoping credentials were not needed to get this information. I'll have to approach this from another direction.
Thanks again!
If you have the required setup (for example WinRM) you can run Get-CimInstance with the ComputerName parameter.
See Example 7 in the cmdlet doc.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference