How to display vm’s snapshot list in a formatted way in windows event logs? Is there any alternate method to create alarm when snapshot exists more than 24 hours?

This post was originally published on this site

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?



$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:UsersAdministratorVMSnapMonitor.txt

$snapcount = $SnapVMlist.Count

$file= Get-Content C:UsersAdministratorVMSnapMonitor.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

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.