VMware Cloud Community
taooo
Contributor
Contributor
Jump to solution

a list of all avaiable datastore to a vm or group of vms

how may i list all available datastores to one/more VM

datastore the vm can vmotion to it

Reply
0 Kudos
2 Solutions

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

taooo
Contributor
Contributor
Jump to solution

 

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

 

View solution in original post

Reply
0 Kudos
9 Replies
LucD
Leadership
Leadership
Jump to solution

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

taooo
Contributor
Contributor
Jump to solution

thank you!

 

but what shall i put here?

$testType = 'datastoreTests'
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You shouldn't change that, that is the test you want to do.


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

Reply
0 Kudos
taooo
Contributor
Contributor
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you change

$vmName = '<MyVM>'


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

Reply
0 Kudos
taooo
Contributor
Contributor
Jump to solution

yes, i replaced it with my VM's name

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
taooo
Contributor
Contributor
Jump to solution

 

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

 

Reply
0 Kudos
taooo
Contributor
Contributor
Jump to solution

hi this is correct answer!

Reply
0 Kudos