any idea how I can speed this up. Its running very slow
Try if this runs faster
$results = foreach($dc in Get-View -ViewType Datacenter -Property Name){
Get-View -ViewType VirtualMachine -SearchRoot $dc.MoRef -Property $vmProps |
Select Name,
@{N='OS';E={$_.Guest.GuestFullName}},
@{N='vHardware';E={$_.Config.Hardware}},
@{N='Datacenter';E={$dc.Name}},
@{N='PowerState';E={$_.Runtime.PowerState}},
@{N='vCenter';E={([uri]$_.Client.ServiceUrl).Host}}
}
$results | Sort-Object -Property Datacenter |
Export-Csv -Path 'C:\Scripts\vmhardware_report.csv' -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc
Thanks for this. Its very fast.
how do i run it per vcenter and not for all vcenters?
Try like this
$vmProps = 'Name','Guest.GuestFullName','Config.Hardware','Runtime.PowerState'
$results = foreach($dc in Get-View -ViewType Datacenter -Property Name -Server $vc){
Get-View -ViewType VirtualMachine -SearchRoot $dc.MoRef -Property $vmProps -Server $vc |
Select Name,
@{N='OS';E={$_.Guest.GuestFullName}},
@{N='vHardware';E={$_.Config.Hardware}},
@{N='Datacenter';E={$dc.Name}},
@{N='PowerState';E={$_.Runtime.PowerState}},
@{N='vCenter';E={([uri]$_.Client.ServiceUrl).Host}}
}
$results | Sort-Object -Property Datacenter |
Export-Csv -Path 'C:\Scripts\vmhardware_report.csv' -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LUcd thats works.
Also how do I create filter for multiple DCs
foreach($dc in Get-View -ViewType Datacenter -Property Name -filter @{"Name"="DC1, DC2, DC3"-Server $vc)
The right-hand side of the Filter is a RegEx expression, you can give alternative matches by separating them with a '|'
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference