Hi,
I have the script below that fails after about 5 VMs with
Get-VIEvent : 11/10/2018 12:54:35 Get-VIEvent Exception has been thrown by the target of an invocation.
At line:1 char:1
+ Get-VIEvent -Entity $VMs -MaxSamples ([int]::MaxValue) |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-VIEvent], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetEvent
-------------------------------------------------------------------
$Report = @()
$VMs = get-vm |Where-object {$_.powerstate -eq "poweredoff"}
Get-VIEvent -Entity $VMs -MaxSamples ([int]::MaxValue) |
where {$_ -is [VMware.Vim.VmPoweredOffEvent]} |
Group-Object -Property {$_.Vm.Name} | %{
$lastPO = $_.Group | Sort-Object -Property CreatedTime -Descending | Select -First 1
$vm = Get-VM -Name $_.Name
$row = '' | select VMName,Powerstate,PowerOFF
$row.VMName = $vm.Name
$row.Powerstate = $vm.Powerstate
$row.PowerOFF = $lastPO.CreatedTime
$report += $row
}
$report | Sort Name | Export-Csv -Path "C:\temp\Powered_Off_VMs11.csv" -NoTypeInformation -UseCulture
Any help would great.
Thanks
Michael
Which PowerCLI version are you using?
There has been a bug in the Get-VIEvent cmdlet that was fixed in 10.2.0.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You will need to upgrade.
See Welcome PowerCLI to the PowerShell Gallery – Install Process Updates
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference