Get-VMState doesn't work for VM hosted on local machine

Aug 8, 2011 at 4:58 PM

Hi Guys,

When Ever I try to get the state of VM hosted on local machine using Get-VMState, I get following error 

You cannot call a method on a null-valued expression. At C:\Program Files\modules\HyperV\VM.ps1:208 char:52
+             $result=$VSMgtSvc.GetSummaryInformation <<<< ( @( (Get-VMSettingData $vm ).__Path ) ,  @(0,1,2,3,4,100,10
1,102,103,104,105,106,107,108))
    + CategoryInfo          : InvalidOperation: (GetSummaryInformation:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

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
leNotFound".
At C:\Program Files\modules\HyperV\VM.ps1:223 char:80
+             else  {write-Warning ($lStr_GetSummaryInfo  -f [ReturnCode]$result. <<<< returnValue )}
    + CategoryInfo          : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException

 

Get-VMState works fine if I try to get a state of VM hosted on a remote server. Get-VM also works fine , but as I am using Get-VMState in my automated script and don't want to change my script.

Please can anyone tell me solution for this problem

 

Thanks in advance