Invoking GetVirtualHardDiskState from Powershell remotely

I am trying to invoke WMI function GetVirtualHardDiskState remotely. The VHD I'm interested in is located on a samba file share.

I made the script:

test_smb.ps1

$myVar = Get-WmiObject -Namespace "root\virtualization\v2" -Class "Msvm_ImageManagementService"

$myVar.GetVirtualHardDiskState("\\smbserver\smbshare03\MyVM\Virtual Hard Disks\MyVM.vhdx")

It works fine locally, however it does not work remotely:

invoke-command -FilePath .\test_smb.ps1 -ComputerName MyRemoteHost

PSComputerName   : MyRemoteHost

RunspaceId       : bf23a4a9-e4dc-4909-9e01-48c1f98f6ee4

__GENUS          : 2

__CLASS          : __PARAMETERS

__SUPERCLASS     :

__DYNASTY        : __PARAMETERS

__RELPATH        :

__PROPERTY_COUNT : 3

__DERIVATION     : {}

__SERVER         :

__NAMESPACE      :

__PATH           :

Job              : \\HP-DL593\root\virtualization\v2:Msvm_StorageJob.InstanceID="A3125E2F-3627-4942-BC81-CDF7980B9DC0"

ReturnValue      : 4096

State            :

I suspected this was the second-hop issue. So I enabled second-hopping and ran the command with CredSSP authentication.

This worked.

PS C:\Users\natalia.odintsova> invoke-command -FilePath .\test_smb.ps1 -ComputerName MyRemoteHost -credential corp\myname -Authentication CredSSP

(I was prompted for password when running this).

PSComputerName   : MyRemoteHost

RunspaceId       : fe0e2165-6a84-4811-9de2-d728f3062b40

__GENUS          : 2

__CLASS          : __PARAMETERS

__SUPERCLASS     :

__DYNASTY        : __PARAMETERS

__RELPATH        :

__PROPERTY_COUNT : 3

__DERIVATION     : {}

__SERVER         :

__NAMESPACE      :

__PATH           :

Job              :

ReturnValue      : 0

State            : <INSTANCE CLASSNAME="Msvm_VirtualHardDiskState"><PROPERTY NAME="Alignment"

                   TYPE="uint32"><VALUE>1</VALUE></PROPERTY><PROPERTY NAME="FileSize"

                   TYPE="uint64"><VALUE>8225030144</VALUE></PROPERTY><PROPERTY NAME="FragmentationPercentage"

                   TYPE="uint32"><VALUE>3</VALUE></PROPERTY><PROPERTY NAME="InUse"

                   TYPE="boolean"><VALUE>FALSE</VALUE></PROPERTY><PROPERTY NAME="MinInternalSize"

                   TYPE="uint64"><VALUE>42949672960</VALUE></PROPERTY><PROPERTY NAME="PhysicalSectorSize"

                   TYPE="uint32"><VALUE>4096</VALUE></PROPERTY></INSTANCE>

Questions:

Is this indeed the second-hop issue? 

Why this occurs with SMB shares, and not with Cluster Shared Volumes? (with VHD located on CSVs I did not have this issue).

July 10th, 2015 1:23pm

VHDs are just files.  It they are stored on a share then you must query the server host that has them mounted to find them that way.

You can also use Get-VHD

Get-VHD \\smbserver\smbshare03\MyVM\Virtual Hard Disks\MyVM.vhdx

You cannot access a remote share from a remote session.  Second hop restriction.

Free Windows Admin Tool Kit Click here and download it now
July 10th, 2015 2:46pm

Thank you for confirming this is the second hop issue.

Do you have an answer to my second question - why this is not an issue for CSVs? This is remote storage too.  

July 10th, 2015 3:46pm

You cannot access any remote share over a remote session even for CSVs.  It xan be that the clustered shares are being made availaabel over a local reference which would bypass the restriction.  Talk to you admins to understand how they have set this up.

Free Windows Admin Tool Kit Click here and download it now
July 10th, 2015 5:34pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics