Community
I'd like to improve the performance on the following code. Takes over 2 hours to run. I believe the reason its so slow is because of Get-VM. I once saw a Get-View on how to improve Get-VM performance but am not exactly sure how to utilize it. The script searches all the host with in virtual center and produces a list of host with no Virtual Machines. Id like to pull the CPU Flags also of each host returned so I can match like processors if possible.
Thanks
$vcs = @()
$vcs += connect-viserver server01
$vcs += connect-viserver server02
$vcs += connect-viserver server03
$vcs += connect-viserver server04
$allhost = Get-VMHost -Server $vcs
foreach ($virtualhost in $allhost) {
if (-not (get-vmhost -Server $vcs $virtualhost | Get-VM -Server $vcs )) {echo "$virtualhost"}}
Disconnect-VIServer -Confirm:$false
Do you have more than 1 Virtual Center in your environment ?
If yes, you can provide them all at once as input to the Connect-VIServer cmdlet as an array.
With the following code you should be able to list all the ESX servers that have no guests defined on them together with the CPU masks for each ESX server.
$vcs = Connect-VIServer -Server <VC-server-1>,<VC-server-2>,...,<VC-server-n> $allhost = Get-View -ViewType HostSystem -Server $vcs foreach($virtualhost in $allhost){ Write-Host $virtualhost.Name if($virtualhost.vm.count -eq 0){ Write-Host "==> No guest defined" -foregroundcolor red } foreach($cpuInfo in $virtualhost.Hardware.CpuFeature){ Write-Host "CPU Level" ("{0:x}" -f $cpuInfo.Level) Write-Host "`tEax:" $cpuInfo.Eax Write-Host "`tEbx:" $cpuInfo.Ebx Write-Host "`tEcx:" $cpuInfo.Ecx Write-Host "`tEdx:" $cpuInfo.Edx } }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Do you have more than 1 Virtual Center in your environment ?
If yes, you can provide them all at once as input to the Connect-VIServer cmdlet as an array.
With the following code you should be able to list all the ESX servers that have no guests defined on them together with the CPU masks for each ESX server.
$vcs = Connect-VIServer -Server <VC-server-1>,<VC-server-2>,...,<VC-server-n> $allhost = Get-View -ViewType HostSystem -Server $vcs foreach($virtualhost in $allhost){ Write-Host $virtualhost.Name if($virtualhost.vm.count -eq 0){ Write-Host "==> No guest defined" -foregroundcolor red } foreach($cpuInfo in $virtualhost.Hardware.CpuFeature){ Write-Host "CPU Level" ("{0:x}" -f $cpuInfo.Level) Write-Host "`tEax:" $cpuInfo.Eax Write-Host "`tEbx:" $cpuInfo.Ebx Write-Host "`tEcx:" $cpuInfo.Ecx Write-Host "`tEdx:" $cpuInfo.Edx } }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference