Powershell + WMI = null

Having spent a bunch of hours programming Powershell with WMI for managing Hyper-V hosts I’ve come to realized that running pre-beta software can be a pain when it comes to developing. The usual Powershell / WMI combination didn’t return a single machine. When testing on a standard Windows Server 2008 it did of course work immediately. I spent at least 2 hours troubleshooting my script with the WMI Explorer, WMI CIM Browser and all the other usual WMI tools before going to the serverroom to check on one of our Hyper-V hosts.

The Powershell / WMI combination looks like this:

$Server = ‘localhost’
$VM_Service = get-wmiobject -computername $server -namespace rootvirtualization Msvm_VirtualSystemManagementService
$ListofVMs = get-wmiobject -computername $server -namespace rootvirtualization Msvm_ComputerSystem | where {$_.ElementName -like ‘*’}
foreach ($VM in $ListofVMs)
{
$VM.ElementName
}

Saving this with a .ps1-ending and running it from Powershell on a Windows Server 2008 Hyper-V host will return the virtual machines hosted on that machine.

If you were to run this on a Windows Server 2008 R2 Hyper-V host, nothing gets returned. A bug is filed, now I’m just waiting to see if it ends up with a fix or if I’ll have to recode the scripts that are working now.

0 thoughts on “Powershell + WMI = null”

Leave a Reply

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