VMware Cloud Community
sjesse
Leadership
Leadership

Get-Snapshot missed snapshot for 4 days

Any idea why the below code wouldn't report a snapshot for a few days

Get-VM | Get-Snapshot | Where {$_.Created -lt (Get-Date).AddDays(-4)} | Select-Object VM, Description, Created

basically, I count the results,  and if its zero I send an email saying there is none, and if there are some I send a table with some. I have a snapshot that was created May 4, but wasn't reported till May 12, which is much more than the 4 days. I went through the events of the vm and I don't see any restores, I can see when the snapshot was taken and when they were deleted, but no explanation of why I didn't know till much later than I like.

0 Kudos
6 Replies
LucD
Leadership
Leadership

That line looks perfectly ok to report snapshots older than 4 days.

Could it be something went wrong in the further handling of the result?
Or the email could perhaps have ended up in a Spam/Junk folder?


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

0 Kudos
sjesse
Leadership
Leadership

I've been getting an email every day, just not one with snapshots. I count the size array and if its less then 1 I get an email saying no snapshots found. The email I got on the 12th did have valid snapshots listed,plus these extra snapshots should have been related.

0 Kudos
LucD
Leadership
Leadership

I would need to see the code where you test and send the email to further analyse.

Is this running through a Scheduled Task?
Does the Scheduled Task history confirm that it ran every day? Without error?
You could also have a look at the smtp log on your mail server.


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

0 Kudos
sjesse
Leadership
Leadership

I tried to keep it as close as possible with removing things.

$vcUser=""

$vcPassword=""

Connect-VIServer vcenter.fqdn -User $vcUser -Password $vcPassword

$smtpServer = smtp.fqdn

$smtpFrom = "noreply@fqdn"

$smtpTo = @(list of emails)

$smtpToTest = @("list of emails")

$style = "<style>BODY{font-family: Arial; font-size: 10pt;}"

$style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}"

$style = $style + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }"

$style = $style + "TD{border: 1px solid black; padding: 5px; }"

$style = $style + "</style>"

$messageSubject = "Snapshots over 72 hours old"

$pdc_vms = Get-VM | Get-Snapshot | Where {$_.Created -lt (Get-Date).AddDays(-4)} | Select-Object VM, Description, Created

Disconnect-VIServer vcenter.fqdn -Force -Confirm:$false

Connect-VIServer vcenter2.fqdn -User $vcUser -Password $vcPassword

$sdc_vms= Get-VM | Get-Snapshot | Where {$_.Created -lt (Get-Date).AddDays(-4)} | Select-Object VM, Description, Created

Disconnect-VIServer vcenter2.fqdn -Force -Confirm:$false

$vms=$pdc_vms + $sdc_vms

if($vms.Count -gt 0)

{

    $messageBody=$vms | ConvertTo-Html -Head $style | Out-String

}else{

    $messageBody="No Snapshots Found"

}

Send-MailMessage -From $smtpFrom -To $smtpTo -Subject $messageSubject -BodyAsHtml $messageBody -SmtpServer $smtpServer

0 Kudos
LucD
Leadership
Leadership

Ok, you did get the mail with the "No Snapshots Found" entry then?


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

0 Kudos
sjesse
Leadership
Leadership

Yeah that's what is wierd, the job is running and I'm getting the email, just for some reason at that time either I couldn't see any snapshots at all or the two that showed up later where hidden for some reason. I'm thinking of doing some error handling on get-vm possiblly checking to see if it can find the actual vcenter vm and report an error if get-vm doesn't return anything.

0 Kudos