how may i list all available datastores to one/more VM
datastore the vm can vmotion to it
No cmdlet for that afaik, but you could use the CheckRelocate method.
The snippet is for 1 VM, but you can easily adapt this to loop through a number of VMs.
$si = Get-View ServiceInstance
$relCheck = Get-View -Id $si.Content.VmProvisioningChecker
$spec = New-Object -TypeName VMware.Vim.VirtualMachineRelocateSpec
$spec.Datastore = $null
$testType = 'datastoreTests'
$vmName = '<MyVM>'
$vm = Get-VM -Name $vmName
Get-VMHost -VM $vm | Get-Datastore -PipelineVariable ds |
ForEach-Object -Process {
$spec.Datastore = $ds.ExtensionData.MoRef
$relCheck.CheckRelocate($vm.ExtensionData.MoRef,$spec,$testType) |
Select @{N='Datastore';E={$ds.Name}},
@{N='VM';E={$vm.Name}},
@{N='Warning';E={$_.Warning.LocalizedMessage}},
@{N='Error';E={$_.Error.LocalizedMessage}}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
vSphere Client version 6.5.0.33000
Name : Windows PowerShell ISE Host
Version : 5.1.17763.1971
InstanceId : 32255cd3-bcd1-44ee-b547-62e0fa6fba91
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-US
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.Host.ISE.ISEOptions
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
PowerCLI Version
----------------
VMware PowerCLI 12.0.0 build 15947286
---------------
Component Versions
---------------
VMware Common PowerCLI Component 12.0 build 15939652
VMware Cis Core PowerCLI Component PowerCLI Component 12.0 build 15939657
VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 12.0 build 15939655
No cmdlet for that afaik, but you could use the CheckRelocate method.
The snippet is for 1 VM, but you can easily adapt this to loop through a number of VMs.
$si = Get-View ServiceInstance
$relCheck = Get-View -Id $si.Content.VmProvisioningChecker
$spec = New-Object -TypeName VMware.Vim.VirtualMachineRelocateSpec
$spec.Datastore = $null
$testType = 'datastoreTests'
$vmName = '<MyVM>'
$vm = Get-VM -Name $vmName
Get-VMHost -VM $vm | Get-Datastore -PipelineVariable ds |
ForEach-Object -Process {
$spec.Datastore = $ds.ExtensionData.MoRef
$relCheck.CheckRelocate($vm.ExtensionData.MoRef,$spec,$testType) |
Select @{N='Datastore';E={$ds.Name}},
@{N='VM';E={$vm.Name}},
@{N='Warning';E={$_.Warning.LocalizedMessage}},
@{N='Error';E={$_.Error.LocalizedMessage}}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thank you!
but what shall i put here?
$testType = 'datastoreTests'
You shouldn't change that, that is the test you want to do.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thank you, i get error:
Exception calling "CheckRelocate" with "3" argument(s): "A specified parameter was not correct: spec.vm"
At line:14 char:3
+ $relCheck.CheckRelocate($vm.ExtensionData.MoRef,$spec,$testType) |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
yes, i replaced it with my VM's name
Tested again, works for me.
Which vSphere, PowerShell and PowerCLI versions are you running this in?
How did you run the snippet?
Can you show the complete run & error?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
vSphere Client version 6.5.0.33000
Name : Windows PowerShell ISE Host
Version : 5.1.17763.1971
InstanceId : 32255cd3-bcd1-44ee-b547-62e0fa6fba91
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-US
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.Host.ISE.ISEOptions
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
PowerCLI Version
----------------
VMware PowerCLI 12.0.0 build 15947286
---------------
Component Versions
---------------
VMware Common PowerCLI Component 12.0 build 15939652
VMware Cis Core PowerCLI Component PowerCLI Component 12.0 build 15939657
VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 12.0 build 15939655
hi this is correct answer!