Get Windows Version on Hyper-V (without VMM)

On vmware you can query the Windows Version over the GUI.
On a Hyper-V without VMM, you can’t do it really quickly.
Below a quick way to query the Windows Version over wmi if the VM-Guest is turned on.

Adjust the first Line and replace *hv* with your naming conversion of Hyper-V’s. This filter down the AD with your Hyper-V Host’s if they are AD Integrated.

AD Integrated Hyper-V

$hypervs = Invoke-Command -ComputerName $env:logonserver -ScriptBlock { Get-Adcomputer -filter * | ? { $_.Name -like "*hv*" }}
$hypervs = $hypervs.name

foreach ( $hyperv in $hypervs ) {
Clear-Variable vm -ErrorAction SilentlyContinue
$vms = Get-VM -ComputerName $hyperv
write-host -ForegroundColor Yellow $hyperv':' $vms.Count

foreach ( $vm in $vms ) {
Clear-Variable os -ErrorAction SilentlyContinue
"" | Select-Object @{Name="Server"; Expression={$vm.name}},@{Name="OS"; Expression={ if (( Get-CimInstance -ComputerName $vm.VMName Win32_OperatingSystem -ErrorAction SilentlyContinue ).Caption -eq $null ) { "Offline" } else {( Get-CimInstance -ComputerName $vm.VMName Win32_OperatingSystem -ErrorAction SilentlyContinue ).Caption} } }
}
}

By using scripts from this website, you confirm that any liability is rejected and used at your own risk.

Local on a Hyper-V

$hypervs = 'localhost'

foreach ( $hyperv in $hypervs ) {
Clear-Variable vm -ErrorAction SilentlyContinue
$vms = Get-VM -ComputerName $hyperv
write-host -ForegroundColor Yellow $hyperv':' $vms.Count

foreach ( $vm in $vms ) {
Clear-Variable os -ErrorAction SilentlyContinue
"" | Select-Object @{Name="Server"; Expression={$vm.name}},@{Name="OS"; Expression={ if (( Get-CimInstance -ComputerName $vm.VMName Win32_OperatingSystem -ErrorAction SilentlyContinue ).Caption -eq $null ) { "Offline" } else {( Get-CimInstance -ComputerName $vm.VMName Win32_OperatingSystem -ErrorAction SilentlyContinue ).Caption} } }
}
}

By using scripts from this website, you confirm that any liability is rejected and used at your own risk.

Leave a Reply

Your email address will not be published. Required fields are marked *