Tuesday 27 July 2021

Powershell script to check for directory and email if it doesnt exist

Simple script to send an email if a directory or mapped drive doesnt exist. This uses SMTP authentication.

$password = ConvertTo-SecureString 'EnterPassword!' -AsPlainText -Force

$credential = New-Object System.Management.Automation.PSCredential ('username', $password)


if (Test-Path -Path P:\) {

    "Path exists!"

} else {

    send-MailMessage -SmtpServer smtp.office365.com -port 587 -UseSSL -To youremail@organization.com -From senderaddress@organiszation.com -credential $credential -Subject "Your Subject" -Body "Body Contents" -BodyAsHtml -Priority high  

}

 

No comments:

Post a Comment