Hi all!
Is there a better or more elegant way of doing this?
Get-VM *f00* | ForEach-Object{[PSCustomObject]@{ Name =$_.Name; DataCenter = ($_|Get-Datacenter).Name}} | Format-Table -AutoSize
Thanks in advance for your help.
-Chris
Since the more common cmdlets (like Get-VM and Get-Datacenter) are already improved significantly in the latest PowerCLI releases, there is no real gain to be made by using Get-View.
But by changing the order in the pipeline, you can limit the number of calls to Get-Datacenter.
Which, in my tests, resulted in a faster execution (but your mileage may vary).
Get-Datacenter -PipelineVariable dc | Get-VM -Name foo* |
ForEach-Object -Process {
[PSCustomObject]@{
Name = $_.Name
DataCenter = $dc.Name
}
} | Format-Table -AutoSize
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Not sure what you mean by "elegant"?
Faster?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
I'll take faster, please.
Since the more common cmdlets (like Get-VM and Get-Datacenter) are already improved significantly in the latest PowerCLI releases, there is no real gain to be made by using Get-View.
But by changing the order in the pipeline, you can limit the number of calls to Get-Datacenter.
Which, in my tests, resulted in a faster execution (but your mileage may vary).
Get-Datacenter -PipelineVariable dc | Get-VM -Name foo* |
ForEach-Object -Process {
[PSCustomObject]@{
Name = $_.Name
DataCenter = $dc.Name
}
} | Format-Table -AutoSize
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference