0

Is it possible to make the below PowerShell code run faster?

 try {
    $ConnectionObject = Connect-VIServer -Server $vCenterServer -Credential $Cred -Force
} catch {}

if($ConnectionObject -and  $ConnectionObject.IsConnected){
    $AllVMs = Get-VM -Server $vCenterServer

    foreach($vm in $AllVMs) {
            $Cluster = Get-Cluster -VM $vm
            $NetworkAdapters = $vm | Get-NetworkAdapter
            $VMhost = Get-VMHost -VM $vm
            $PortGroups = $NetworkAdapters | Get-VDPortgroup
            #Other code goes here that processes the above 
    }
}  

At the moment it takes forever as there are about 1800 VMs.

Steve
  • 337
  • 4
  • 11

0 Answers0