Skip to content

Instantly share code, notes, and snippets.

@I90Runner
Forked from 9to5IT/Get-VCEvents.ps1
Created February 3, 2018 04:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save I90Runner/a92a2ee0160c20a7c6c448447ed7c19c to your computer and use it in GitHub Desktop.
Save I90Runner/a92a2ee0160c20a7c6c448447ed7c19c to your computer and use it in GitHub Desktop.
PowerShell: Collect vCenter Events
#-----------------------------------------------------------------------------
# Import PowerCLI Module
#-----------------------------------------------------------------------------
Add-PSSnapin VMware.VimAutomation.Core
#-----------------------------------------------------------------------------
# Connect to vCenter Server
#-----------------------------------------------------------------------------
$Server = Read-Host 'Specify the vCenter Server or ESXi Host to connect to (IP or FQDN)?'
Connect-VMwareServer -VMServer $Server
#-----------------------------------------------------------------------------
# Get Events from vCenter (filtering on event type)
#-----------------------------------------------------------------------------
Get-VIEvent -maxsamples 10000 -Start "01/08/2015" -Finish "05/08/2015" | Where-Object {$_.Gettype().Name-eq "VmCreatedEvent" -or $_.Gettype().Name-eq "VmBeingClonedEvent" -or $_.Gettype().Name-eq "VmBeingDeployedEvent"} | Sort-Object CreatedTime -Descending |Select-Object CreatedTime, UserName, FullformattedMessage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment