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

No, I meant like this

 

 

Connect-VIServer-server$vcenterserver$date=Get-Date$VMsWithSnaps=@(Get-VM|Get-Snapshot|SelectVM,Name,Created,sizemb)# Make sure the body isn't empty. If it is, skip this part and exit the script.if($VMsWithSnaps-ne$null){    $body=@("
        <center><tableborder=1width=50%cellspacing=0cellpadding=8bgcolor=Blackcols=3>
       
<trbgcolor=White><td>VirtualMachine</td><td>Snapshot</td><td>SizeinMB</td><td>CreationTime</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
    } }else{    Send-MailMessage-To"$toAddr"-From"$fromAddr"-Subject"WARNING: NO VMware Snapshots found on msf1vvcs01p"-Body""-SmtpServer"$smtpsrv"
}
Disconnect-VIServer-Server$vcenterserver-Confirm:$falseexit

Viewing all articles
Browse latest Browse all 252940

Trending Articles



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