Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 252940

Re: PowerCLI script to alert on snapshots in vSphere

$
0
0

So does this make sense, i added in the info listed in red.

 

 

Connect-VIServer -server $vcenterserver

$date = Get-Date

$VMsWithSnaps = @(Get-VM | Get-Snapshot | Select VM,Name,Created,sizemb)

 

# Make sure the body isn't empty. If it is, skip this part and exit the script.
if($VMsWithSnaps -ne $null)Else{
Send-MailMessage -To "$toAddr" -From "$fromAddr" -Subject "WARNING: NO VMware Snapshots found on msf1vvcs01p" -Body "$body" -SmtpServer "$smtpsrv" -BodyAsHtml
{
    $body = @("
    <center><table border=1 width=50% cellspacing=0 cellpadding=8 bgcolor=Black cols=3>
    <tr bgcolor=White><td>Virtual Machine</td><td>Snapshot</td><td>Size in MB</td><td>Creation Time</td></tr>")


    $i = 0

    do {
    if($i % 2){$body += "<tr bgcolor=#D2CFCF><td>$($VMsWithSnaps[$i].VM)</td><td>$($VMsWithSnaps[$i].Name)</td><td>$($VMsWithSnaps[$i].Sizemb)</td><td>$($VMsWithSnaps[$i].Created)</td></tr>";$i++}
    else {$body += "<tr bgcolor=#EFEFEF><td>$($VMsWithSnaps[$i].VM)</td><td>$($VMsWithSnaps[$i].Name)</td><td>$($VMsWithSnaps[$i].Sizemb)</td><td>$($VMsWithSnaps[$i].Created)</td></tr>";$i++}
    }
    while ($VMsWithSnaps[$i] -ne $null)

    $body += "</table></center>"

# Send email alerting recipients about snapshots.
if($attachmentPref){
$VMsWithSnaps | Export-CSV "SnapshotReport $($date.month)-$($date.day)-$($date.year).csv"
Send-MailMessage -To "$toAddr" -From "$fromAddr" -Subject "WARNING: VMware Snapshots found on msf1vvcs01p" -Body "$body" -Attachments "SnapshotReport $($date.month)-$($date.day)-$($date.year).csv" -SmtpServer "$smtpsrv" -BodyAsHtml
Remove-Item "SnapshotReport $($date.month)-$($date.day)-$($date.year).csv"
}
Else{
Send-MailMessage -To "$toAddr" -From "$fromAddr" -Subject "WARNING: VMware Snapshots found on msf1vvcs01p" -Body "$body" -SmtpServer "$smtpsrv" -BodyAsHtml
}
}

Disconnect-VIServer -Server $vcenterserver -Confirm:$false
exit


Viewing all articles
Browse latest Browse all 252940

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>