any idea how to optimize this. runs very slow
Where do you populate $vms?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
right after the first for loop
That line wasn't there in the original post.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
i edited it
Try something like this
Updated the Cluster calculation method!
Get-View -ViewType Datacenter -Property 'Name' -PipelineVariable dc |
ForEach-Object -Process {
Get-View -ViewType Datastore -SearchRoot $dc.MoRef -Property 'Name','Summary.Capacity','VM' -Filter @{VM='.'} -PipelineVariable ds |
ForEach-Object -Process {
Get-View -Id $ds.VM |
ForEach-Object -Process {
[PSCustomObject]@{
Datastore = $ds.name
VMName = $_.name
PowerState = $_.Runtime.PowerState
Cluster = (Get-View -Id (Get-View -Id $_.Runtime.Host -Property Parent).Parent -Property Name).Where{$_ -is [VMware.Vim.ClusterComputeResource]}.Name
Datacenter = $dc.Name
CapacityGB = [math]::Round($ds.Summary.Capacity/1GB,2)
}
}
}
} | Format-Table -AutoSize
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thank Luc. how do i filter based on a a vcenter and datastore names?
To filter on one or more vCenters, use the Server parameter on the Get-View cmdlets.
To filter on Datastore names, use the Filter parameter.
Get-View -ViewType Datastore -SearchRoot $dc.MoRef -Property 'Name','Summary.Capacity','VM' -Filter @{VM='.';Name='ds1|ds2|ds3'} -PipelineVariable ds |
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference