VM Created and Deleted events using PowerCLI

A quick one liner to find the the users who created or deleted the VM in the past 7 days. This can be fetched using the TaskEvent which has the description VmBeingDeployedEvent or VmBeingClonedEvent and VmRemovedEvent . If you want  to know the count for longer period then change the number AddDays to longer value

Here is code for getting the VM creation

Get-VIEvent -MaxSamples ([int]::MaxValue) -Start (Get-Date).AddDays(-30) |

where {$_.Gettype().Name -eq “VmCreatedEvent” -or $_.Gettype().Name -eq “VmBeingClonedEvent” -or $_.Gettype().Name -eq “VmBeingDeployedEvent”} |

%{“{0} created by {1}” -f $_.VM.Name,$_.UserName}

Here is code for getting the VM Deletion

Get-VIEvent -MaxSamples ([int]::MaxValue) -Start (Get-Date).AddDays(-7) | where {$_.Gettype().Name -eq “VmRemovedEvent”} |  %{“{0} created by {1}” -f $_.VM.Name,$_.UserName}


You must be logged in to post a comment.

Proudly powered by WordPress   Premium Style Theme by www.gopiplus.com