I was able to create events and display vm snaphot which exists more then 24 hours. But vms created appear in a single line as shown in first image in windows event logs. Please let me know how to get the desired out image in which vms should appear one below the other.
Also if there is any alternate method to create alarm when snapshot exists for more than 24 hours would be helpful?
Code-
$SnapVMlist = Get-VM | Get-Snapshot | Where {$_.Created -lt [datetime]::Now.AddDays(-1)} | Select VM, Name, Created
Get-VM | Get-Snapshot | Where {$_.Created -lt [datetime]::Now.AddDays(-1)} | Select-Object VM, Name, Created | Out-File -FilePath C:\Users\Administrator\VMSnapMonitor.txt
$snapcount = $SnapVMlist.Count
$file= Get-Content C:\Users\Administrator\VMSnapMonitor.txt
New-EventLog -LogName System -Source GMES2
if ($snapcount.count -gt 0){
eventcreate /ID 102 /L SYSTEM /T ERROR /SO "GMES2" /D "$file"
}
Any assistance that I can get would be much appreciated.
Thank you