none
Get-WmiObject fails as non-Administrator

    Domanda

  • I'm using a variant of this script to test the KVP functionality on Hyper-V:

    http://blogs.msdn.com/b/virtual_pc_guy/archive/2008/11/18/hyper-v-script-looking-at-kvp-guestintrinsicexchangeitems.aspx

    On a Win2K8R2 server with a user (which has Administrator privileges) the script fails to run this command:

    # Get the virtual machine object
    $query = "Select * From Msvm_ComputerSystem Where ElementName='" + $VMName + "'"
    $Vm = gwmi -namespace root\virtualization -query $query -computername $HyperVServer

    The error is like this:

    PS C:\Users\Public\Downloads> .\hyper-v.kvptest.ps1
    Specify the Hyper-V Server to use (enter '.' for the local computer): .
    Specify the name of the virtual machine: Factory
    Get-WmiObject : Invalid object path
    At C:\Users\Public\Downloads\hyper-v.kvptest.ps1:45 char:12
    + $Kvp = gwmi <<<<  -namespace root\virtualization -query $query -computername $HyperVServer
        + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException
        + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand


    Guest KVP information for Factory
    You cannot call a method on a null-valued expression.
    At C:\Users\Public\Downloads\hyper-v.kvptest.ps1:17 char:48
    +    foreach ($CimProperty in $CimXml.SelectNodes <<<< ("/INSTANCE/PROPERTY[@NAME='Name']"))
        + CategoryInfo          : InvalidOperation: (SelectNodes:String) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:\Users\Public\Downloads\hyper-v.kvptest.ps1:22 char:48
    +    foreach ($CimProperty in $CimXml.SelectNodes <<<< ("/INSTANCE/PROPERTY[@NAME='Data']"))
        + CategoryInfo          : InvalidOperation: (SelectNodes:String) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull

    System.Object

    Any idea why this script needs to run with Admin permissions, even if the user is an Administrator?

    Is there a way to let it run without Administrator permissions?

    Thanks.

    mercoledì 27 giugno 2012 17:53

Risposte

  • These errors happen also when it runs on Windows Server 2012 as Administrator.

    Looks like the whole script needs an update to cope.


    The error is like this:

    Get-WmiObject : Invalid object path
    At C:\Users\Public\Downloads\hyper-v.kvptest.ps1:45 char:12
    + $Kvp = gwmi <<<<  -namespace root\virtualization -query $query -computername $HyperVServer
        + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException
        + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

    This error is specific to the non-Administrator account.

    Guest KVP information for Factory
    You cannot call a method on a null-valued expression.
    At C:\Users\Public\Downloads\hyper-v.kvptest.ps1:17 char:48
    +    foreach ($CimProperty in $CimXml.SelectNodes <<<< ("/INSTANCE/PROPERTY[@NAME='Name']"))
        + CategoryInfo          : InvalidOperation: (SelectNodes:String) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:\Users\Public\Downloads\hyper-v.kvptest.ps1:22 char:48
    +    foreach ($CimProperty in $CimXml.SelectNodes <<<< ("/INSTANCE/PROPERTY[@NAME='Data']"))
        + CategoryInfo          : InvalidOperation: (SelectNodes:String) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull

    System.Object

    giovedì 28 giugno 2012 09:12

Tutte le risposte

  • It has been my experience that this is an issue with UAC. If you right-click the PowerShell and "Run as Administrator" (as the non-administrator user), and then run the script, do you achieve success?

    G. Samuel Hays

    mercoledì 27 giugno 2012 19:29
  • These errors happen also when it runs on Windows Server 2012 as Administrator.

    Looks like the whole script needs an update to cope.


    The error is like this:

    Get-WmiObject : Invalid object path
    At C:\Users\Public\Downloads\hyper-v.kvptest.ps1:45 char:12
    + $Kvp = gwmi <<<<  -namespace root\virtualization -query $query -computername $HyperVServer
        + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException
        + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

    This error is specific to the non-Administrator account.

    Guest KVP information for Factory
    You cannot call a method on a null-valued expression.
    At C:\Users\Public\Downloads\hyper-v.kvptest.ps1:17 char:48
    +    foreach ($CimProperty in $CimXml.SelectNodes <<<< ("/INSTANCE/PROPERTY[@NAME='Name']"))
        + CategoryInfo          : InvalidOperation: (SelectNodes:String) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:\Users\Public\Downloads\hyper-v.kvptest.ps1:22 char:48
    +    foreach ($CimProperty in $CimXml.SelectNodes <<<< ("/INSTANCE/PROPERTY[@NAME='Data']"))
        + CategoryInfo          : InvalidOperation: (SelectNodes:String) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull

    System.Object

    giovedì 28 giugno 2012 09:12