VMware Cloud Community
TheVMinator
Expert
Expert
Jump to solution

Validate storage vmotion compatibility with powerCLI

If I use vSphere Web Client to storage vMotion a VM, it does a compatibility / validation when I select the datastore and tells me whether the storage vmotion will succeed before I try it.  If there are any issues such as the datastore isn't mounted to the ESXi host the VM is on - it will tell me before I attempt the sVmotion and the compatibility check / validation will fail.

What I'd like to do is take a VM I'm about to sVmotion and do a compatibility check before I actually attempt the storage vMotion and see if there are any issues first.

Can this be done in PowerCLI?

Thanks!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try the following method, I think that is more like the Web Client is showing.

$vmName = 'MyVM'

$tgtDSName = 'MyDS'

$vm = Get-VM -Name $vmName

$ds = Get-Datastore -Name $tgtDSName

$si = Get-View ServiceInstance

$vmProvCheck = Get-View -Id $si.Content.VmProvisioningChecker

$spec = New-Object VMware.Vim.VirtualMachineRelocateSpec

$spec.Datastore = $ds.ExtensionData.MoRef

$result = $vmProvCheck.CheckRelocate($vm.ExtensionData.MoRef,$spec,$null)

$result | %{

    $_.Error | Select @{N='Message';E={$_.LocalizedMessage}}

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

No cmdlet for that I'm afraid, but the RecommendDatastores method should be able to provide that information.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

TheVMinator
Expert
Expert
Jump to solution

OK thanks again. That might actually work. But how would I use it? How would I compare the data store that I want to move my VM to to the list of recommended data stores and see if the data store I want to move it to is in the list?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try the following method, I think that is more like the Web Client is showing.

$vmName = 'MyVM'

$tgtDSName = 'MyDS'

$vm = Get-VM -Name $vmName

$ds = Get-Datastore -Name $tgtDSName

$si = Get-View ServiceInstance

$vmProvCheck = Get-View -Id $si.Content.VmProvisioningChecker

$spec = New-Object VMware.Vim.VirtualMachineRelocateSpec

$spec.Datastore = $ds.ExtensionData.MoRef

$result = $vmProvCheck.CheckRelocate($vm.ExtensionData.MoRef,$spec,$null)

$result | %{

    $_.Error | Select @{N='Message';E={$_.LocalizedMessage}}

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
TheVMinator
Expert
Expert
Jump to solution

Great help - OK thanks again

0 Kudos