New-VM - Get-WmiObject : Invalid class

Jun 11, 2012 at 3:36 PM

I am getting the following error when running New-VM

Get-WmiObject : Invalid class
At C:\Program Files\Modules\hyperv\VM.ps1:437 char:34
+         $VSMgtSvc = Get-WmiObject <<<<  -ComputerName $Server -Namespace $HyperVNamespace -Class "MSVM_VirtualSystemM
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

You cannot call a method on a null-valued expression.
At C:\Program Files\Modules\hyperv\VM.ps1:443 char:53
+                 $result = $VSMgtSvc.DefineVirtualSystem <<<< ($GlobalSettingsData.GetText([System.Management.TextForm
at]::WmiDtd20), $null, $null)
    + CategoryInfo          : InvalidOperation: (DefineVirtualSystem:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Test-WMIResult : Cannot validate argument on parameter 'result'. The argument is null or empty. Supply an argument that
 is not null or empty and then try the command again.
At C:\Program Files\Modules\hyperv\VM.ps1:445 char:47
+                 if ( ($Result | Test-wmiResult <<<<  -wait:$wait -JobWaitText (($lstr_VMCreating -f $Server) + $_)`
    + CategoryInfo          : InvalidData: (:) [Test-WMIResult], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Test-WMIResult

Cannot convert null to type "ReturnCode" due to invalid enumeration values. Specify one of the following enumeration va
lues and try again. The possible enumeration values are "OK, JobStarted, Failed, AccessDenied, NotSupported, Unknown, T
imeout, InvalidParameter, SystemInUse, InvalidStateForOperation, IncorrectDataType, SystemNotAvailable, OutOfMemory, Fi
At C:\Program Files\Modules\hyperv\Helper.ps1:327 char:123
+     Else                                                                    {write-error ($failText + [returnCode]$Re
sult. <<<< ReturnValue)      ;[ReturnCode]::Failed }
    + CategoryInfo          : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException

Jun 11, 2012 at 6:14 PM

I found out what the issue was.  I had UAC enabled which was not elevating the premissions for VM.ps1 when it ran.