Hello,
I found the folllowing code but not able to figure it out. The ouput is not what I want.
Get-VM | Select Name, @{N="Cluster";E={Get-Cluster -Name "Site1UCSCluster01" }}, @{N="ESX Host";E={Get-VMHost -VM $_}},@{N="Datastore";E={Get-Datastore -VM $_}} |fl
But, the output is wrong those VMs do not reside on Site1UCSCluster01:
Name : CBEDM
Cluster : Site1UCSCluster01
ESX Host : Host1
Datastore : CBEDM-DS3-R5
Name : CBEDMTest
Cluster : Site1UCSCluster01
ESX Host : Host2
Datastore : CBTEST-DS1-R5
thanks for ur help,
Then try it like this
$clusterName = "MyCluster"
Get-Cluster -Name $clusterName | Get-VM |
Select Name,
@{N="Cluster";E={$clusterName}},
@{N="ESX Host";E={Get-VMHost -VM $_ | Select -ExpandProperty Name}},
@{N="Datastore";E={Get-Datastore -VM $_ | Select -ExpandProperty Name}} |
fl
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That line does not only list VMs on a specific cluster, it lists all VMs and then tries to report on which cluster they are.
But unfortunately it will not work that way, the VM parameter is required instead of the Name parameter
Try it like this
Get-VM |
Select Name,
@{N="Cluster";E={Get-Cluster -VM $_ | Select -ExpandProperty Name}},
@{N="ESX Host";E={Get-VMHost -VM $_ | Select -ExpandProperty Name}},
@{N="Datastore";E={Get-Datastore -VM $_ | Select -ExpandProperty Name}} |
fl
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hmm, now it is listing all the clusters, what if I want a specified cluster...
Then try it like this
$clusterName = "MyCluster"
Get-Cluster -Name $clusterName | Get-VM |
Select Name,
@{N="Cluster";E={$clusterName}},
@{N="ESX Host";E={Get-VMHost -VM $_ | Select -ExpandProperty Name}},
@{N="Datastore";E={Get-Datastore -VM $_ | Select -ExpandProperty Name}} |
fl
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference