function sendMail1($body) { $smtpServer = "192.168.1.25" $emailFrom = "snapshots@email.ie" $emailTo = ("alerts@email.com") $subject1 = "No .avhd files (snapshots) found" Send-MailMessage -From $emailFrom -To $emailTo -Subject $subject1 -Body $body -SmtpServer $smtpServer } function sendMail2($body) { $smtpServer = "192.168.1.25" $emailFrom = "snapshots@email.ie" $emailTo = ("alerts@email.com") $subject = "ALERT!! snapshots found - Urgent action required" Send-MailMessage -From $emailFrom -To $emailTo -Subject $subject -Body $body -SmtpServer $smtpServer } $output = Get-ChildItem C:\ClusterStorage\ * -include *.avhd -recurse If ($output -eq $NULL) { #Do nothing #$msg = "No .avhd files (snapshots) found" #sendMail1($msg) } Else { #send the email $msg = out-string -inputobject $output sendMail2($msg) }
Thursday, 13 September 2012
powershell script to check for hyper-v snapshots and email if they are found or not
Simple powershell script to check for hyper-v snapshots and email if they are found or not
Labels:
hyper-v,
powershell,
scripting,
windows
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment