VMware Cloud Community
tdubb123
Expert
Expert

script running slow

any idea how I can speed this up. Its running very slow

Screen Shot 2018-05-18 at 9.26.50 AM.png

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership

Try if this runs faster

$vmProps = 'Name','Guest.GuestFullName','Config.Hardware','Runtime.PowerState'

$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

Reply
0 Kudos
tdubb123
Expert
Expert

Hi Luc

Thanks for this. Its very fast.

how do i run it per vcenter and not for all vcenters?

Reply
0 Kudos
LucD
Leadership
Leadership

Try like this

$vc = 'MyVC'


$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

Reply
0 Kudos
tdubb123
Expert
Expert

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)

Reply
0 Kudos
LucD
Leadership
Leadership

The right-hand side of the Filter is a RegEx expression, you can give alternative matches by separating them with a '|'

foreach($dc in Get-View -ViewType Datacenter -Property Name -filter @{"Name"="DC1|DC2|DC3"-Server $vc)


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

Reply
0 Kudos