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-VMHost | Get-Cluster | |
---|---|---|---|
original way | 1 | 1000 | 1000 |
as written here | 1 | 0 | 0 |
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?