Skip to content

Instantly share code, notes, and snippets.

@gmassawe
Last active May 13, 2018 19:26
Show Gist options
  • Save gmassawe/89cb998250bacf8f472e7fa2e68ba96a to your computer and use it in GitHub Desktop.
Save gmassawe/89cb998250bacf8f472e7fa2e68ba96a to your computer and use it in GitHub Desktop.
PowerShell script to check file change date/time then email using Office365
<#
.SYNOPSIS
Script to check file change date and time
.NOTES
Version: 1.0
Author: George Massawe
Creation Date: 03/18/2018
Purpose/Change: Initial script development
#>
$SMTPServer = "smtp.office365.com"
$SMTPPort = "587"
$SMTPCred = (Get-Credential)
$EmailFrom = "server@company.com"
$EmailTo = "youremail@company.com"
$Cc = "anotheremail@company.com"
$EmailSubject = "Email Subject"
$NewDoc = "\\PATH\TO\YOUR\FILE"
$FileDate = (Get-ChildItem $NewDoc).lastwritetime
$EmailBody = @"
<p> Your email message here <b> $FileDate </b>.</p>
<p> This message was generated automatically.</p>
"@
$MailMessage = @{
Smtpserver = $SMTPServer
Port = $SMTPPort
Credential = $SMTPCred
From = $EmailFrom
To = $EmailTo
Cc = $Cc
Subject = $EmailSubject
Body = $EmailBody
}
Send-MailMessage -UseSsl @MailMessage -BodyAsHtml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment