#PowerShell Script to monitor the uptime
#This script will send an email notification to a single or group of people when the VM is running for more than 3 hours
$EmailFrom = “username@domain.com“
$EmailTo = “user1@domain.com, user2@domain.com, user3@domain.com“
$Subject = “Alert: Azure VM running more than 3 hours”
$Body = “Azure High-end VM (Name) running for more than 3 hours. Please Turn OFF the VM if not in use..”
$SMTPServer = “outlook.office365.com”
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“username@domain.com”, “password”);
$SMTPClient.Send($EmailFrom,$EmailTo,$Subject,$Body)
# set the script to sleep for 1 Hour
start-sleep 3600
$EmailFrom = “username@domain.com“
$EmailTo = “user1@domain.com, user2@domain.com, user3@domain.com“
$Subject = “Second Alert: Azure VM running more than 4 hours“
$Body = “Azure High-end VM (Name) running for more than 4 hours. Please Turn OFF the VM if not in use..“
$SMTPServer = “outlook.office365.com”
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“username@domain.com”, “password”);
$SMTPClient.Send($EmailFrom,$EmailTo,$Subject,$Body)