Thx, I see how much time is executed
Full version
function Get-VIEventPlus { ... }
$name="1. Ann1"
$name1="2. Ann2"
$name2="3. Ann3"
$name3="4. Ann4"
$myCol = @()
$ESXHosts = Get-VMHost | select -Exp Name
foreach ($ESXHost in $ESXHosts){
$RPs = Get-ResourcePool -Location $ESXHost | ?{$_.Name -ne "Resources"}
$VMs = Get-VM -Location $ESXHost
foreach ($VM in $VMs){
$Ann = $vm | Get-Annotation -CustomAttribute $name, $name1, $name2 ,$name3
$VIe = Get-VIEventPlus -Entity $VM -EventType VmPoweredOnEvent | Where-Object {$_.userName -ne ""`
-and $_.userName -ne "User" -and $_.userName -ne "vpxuser"`
-and $_.userName -ne "admin1" -and $_.userName -ne "admin2"`
-and $_.userName -ne "admin3" -and $_.userName -ne "admin4"`
-and $_.userName -ne "admin5"} |
Sort-Object -Property CreatedTime,Vm.Name,UserName -Descending -Unique |
Group-Object -Property {$_.Vm.Name} | %{
$_.Group | Sort-Object -Property CreatedTime -Descending |
Select -First 1 UserName}
$Details = "" | Select ESXHost,ResourcePool,VMName,$name,$name1,$name2,$name3,UserName
$Details.ESXHost = $ESXHost
$Details.ResourcePool = $VM.ResourcePool.Name
#$Details.VMName = $Ann.AnnotatedEntity[0] | select -Exp Name
$Details.VMName = $VM.Name
$Details.$name = $Ann.value[0]
$Details.$name1 = $Ann.value[1]
$Details.$name2 = $Ann.value[2]
$Details.$name3 = $Ann.value[3]
$Details.UserName = $VIe.userName | Out-String
$myCol += $Details
}
}
$myCol | Export-Csv
P.s. How to insert the text of the script with the release of color?