VMware Cloud Community
AymanSammour
Contributor
Contributor

Snapshot created by

I have the below script works fine, but the issue I am having, some of the returned results do not have the Created by user; and if the tasked was scheduled it will also not populate the created by, any help would be appreciated 

foreach ($snap in Get-VM | Get-Snapshot)

{$snapevent = Get-VIEvent -Entity $snap.VM -Types Info -Finish $snap.Created -MaxSamples 1 | Where-Object {$_.FullFormattedMessage -imatch 'Task: Create virtual machine snapshot'}

if ($snapevent -ne $null){Write-Host ( "VM: "+ $snap.VM + ". Snapshot '" + $snap + "' created on " + $snap.Created.DateTime + " by " + $snapevent.UserName +".")}

else {Write-Host ("VM: "+ $snap.VM + ". Snapshot '" + $snap + "' created on " + $snap.Created.DateTime + ". This event is not in vCenter events database")}}

0 Kudos
3 Replies
LucD
Leadership
Leadership

If the information is not in the TaskEvent, I'm not sure that information is even available at all.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
AymanSammour
Contributor
Contributor

but this is only happening when a snapshot  task  is Scheduled

0 Kudos
LucD
Leadership
Leadership

Yes, indeed.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos