Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 252940

Re: Ineficient script ?

$
0
0

Hello, baobabcat-

 

Yes, I would guess that that script might take a while to run.  Instead of making those Get-Cluster and Get-VMHost calls once per VM, you can write a similar script that makes far fewer calls, helping the speed.  Like:

 

ForEach ($Serverin$connectioninfo) {
   
$strVISrvName=$Server.Management_Server
   
Write-Host$strVISrvName
   
Connect-VIServer$strVISrvName
   
   
## one Get-VM per vCenter
    Get-VM | Where-Object {$_.PowerState -eq"PoweredOn"-and$_.Name -notlike"UK1*"} | Select @{N="VC_Server";E={$strVISrvName}}, Name, @{N="Cluster";E={$_.VMHost.Parent.Name}}, `
    @{N
="ESX Host";E={$_.VMHost.Name}} | Export-Csv-NoTypeInformation -Append $outputfile
   
   
Disconnect-VIServer-Confirm:$False
}
## end foreach

 

This just using the Get-VM cmdlet, and accesses the VMHost and Cluster names via the properties of the VMs that are returned.

 

So, for example, if you have a vCenter with 5 clusters and 1000 VMs total, the number of cmdlet calls in the original way and in this way for just one vCenter:

 

Get-VM
Get-VMHostGet-Cluster
original way110001000
as written here100

 

You could also get more serious and employ the Get-View cmdlet, which allows for further speed optimization.  But, how does this change do for you?


Viewing all articles
Browse latest Browse all 252940

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>