I'm attempting to take a simplistic approach to my snapshot reporting by using the following script. I would like to add one more header to indicate who created by extracting the information via Get-VIEvent.
How can I incorporate $snapevent = Get-VIEvent -Entity $snap.VM -Types Info -Finish $snap.Created -MaxSamples 1 | Where-Object {$_.FullFormattedMessage -imatch 'Task: Create virtual machine snapshot'}
into the below script?
connect-viserver -server localhost
$report = Get-VM | Get-Snapshot | where { $_.Created -lt (Get-Date).AddDays(-15)} | select VM, Name, Created, Creator
$emailFrom = "Test@test.com"
$emailTo = "Test@test.com"
$subject = "VM Snapshots older then 15 days"
$body = $report | Out-String
$smtpServer = "Relay@test.com"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)
disconnect-viserver -confirm:$false
Craig