Logging an Event into Windows Event Logs


Im trying to use the attached script file to log an event into the Windows Event Logs when the last previous version was more than 3 days old.

Im guessing I will need to add an IF statement in with something along the lines of.

if $Object.LatestShadowCopy lt (get-date).adddays 3 Write-EventLog Application -Source “VSS Monitoring” -EventId 0 -Message “No Shadow Copies created recently” -EntryType error
Else Continue

But im a bit clueless how to format this correctly in the script.

Any advice would be greatly appreciated.

Was something like this what you had in mind?

if ((.\Get-ShadowCopyStats.ps1 -ServerName $env:COMPUTERNAME).LatestShadowCopy -lt (Get-Date).AddDays(-3)) {
Write-EventLog -LogName Application -Source ‘VSS Monitoring’ -EventId 0 -Message ‘No Shadow Copies created recently’ -EntryType Error

This will generate an error unless you first create the custom source named ‘VSS Monitoring’:

New-EventLog –LogName Application –Source ‘VSS Monitoring’

Although I’m using the New-EventLog cmdlet in the previous one-liner, it actually doesn’t create a new eventlog, instead it creates a new ‘source’ for the existing application log.


Hi Mike

that works great, but im having a problem where there’s more than one drive with shadow copy enabled. I assume this is because there would be two .LatestShadowCopy in the output (one for each drive) I tried putting a for each in the if statement but that didn’t seem to work. Any ideas?

Many thanks

Hi All

Im still struggling with this issue, if anyone has any thoughts on how to get this working it would be very much appreciated


Hi All

Im still struggling with this issue, appreciate any help if you have the time.


Could you please clarify what you’re having a problem with? Is it writing to the event log? Formatting a message? You said you’re, “having a problem where there’s more than one drive…” but you didn’t say what, exactly, the problem was. If you’re able to provide some more detail on what you want to happen, and what problem you’re having, it might be easier for folks to offer advice.


what happens if you do:

.\Get-ShadowCopyStats.ps1 -ServerName $env:COMPUTERNAME | foreach { if($_.LatestShadowCopy -lt (Get-Date).AddDays(-3)){ Write-EventLog -LogName Application -Source 'VSS Monitoring' -EventId 0 -Message 'No Shadow Copies created recently' -EntryType Error } }