How to accelerate work of the command Get-TagAssignment
Since at increase in number of required tags time increases multiply
simple script for test
$LOGFile = "C:\Reports\=VM-info-CPUlevel.csv" $LOG = New-Object PSObject Add-Member -InputObject $LOG -MemberType NoteProperty -Name VMname -Value "VM name" Add-Member -InputObject $LOG -MemberType NoteProperty -Name OS -Value "VM OS" Add-Member -InputObject $LOG -MemberType NoteProperty -Name vCPU -Value "vCPU" Add-Member -InputObject $LOG -MemberType NoteProperty -Name vMEM -Value "vMEM" Add-Member -InputObject $LOG -MemberType NoteProperty -Name VMtag -Value "CPUlevel" Add-Member -InputObject $LOG -MemberType NoteProperty -Name ESX -Value "ESXi" $VMs = get-vm $Currenttime = get-date -format "HH:mm:ss" Write-Host "Start - "$Currenttime -ForegroundColor Magenta Write-Host "Total VMs - "$VMs.count -ForegroundColor Cyan foreach ($VM in $VMs) { # $VM = $VMs $LOG.ESX = $VM.VMHost.name $VMinfo = $VM $LOG.VMname = $VM.name $LOG.OS = $VMinfo.Guest.OSFullName $LOG.vCPU = $VMinfo.NumCpu $LOG.vMEM = $VMinfo.MemoryGB # get tag $LOG.VMtag = ($VM | Get-TagAssignment –Category "CPUlevel").Tag.name Export-Csv -path $LOGFile -InputObject $LOG -Encoding UTF8 -Append $LOG.VMname = $VM.name $LOG.OS = $null $LOG.vCPU = $null $LOG.vMEM = $null $LOG.VMtag = $null } $Currenttime = get-date -format "HH:mm:ss" Write-Host "Stop - "$Currenttime -ForegroundColor yellow
Performance of a simple script without inquiry of a tag makes 3 seconds.
Image may be NSFW.
Clik here to view.
Performance of a simple script from inquiry of a tag makes the 5 minutesand 2 seconds.