Script – Send a Message to Employees Celebrating their Work Anniversary

I have posted this on Spiceworks but figured I should post it here as well.

#Thanks to the following sources

# Define local Exchange server info for message relay. Ensure that any servers running this script have permission to relay.
$ExchangeServer = ""
$SMTPPort = "25"
$FromAddress = "AnniversaryTeam <>"

# Function to create report email
function SendNotification{
 $Msg = New-Object Net.Mail.MailMessage
 $Smtp = New-Object Net.Mail.SmtpClient($ExchangeServer, $SMTPPort);
 $Msg.From = $FromAddress
 $Msg.Subject = "Happy Anniversary!"
 $Msg.Body = $EmailBody
 $Msg.IsBodyHTML = $true

# Import user list and information from .CSV file and get today's date
$Date = Get-Date
$Users = Import-Csv C:\Scripts\Anniversary.csv
# Send notification to each user in the list whose anniversary is today
Foreach ($User in $Users) {
if ($Date.Day -eq $User.Anniversary_day -and $Date.Month -eq $User.Anniversary_month) {
 $ToAddress = $User.Email
 $Name = $User.FirstName
 $EmailBody = @"
 <p>Dear $Name,</p>
 <p>Today is your work anniversary! We appreciate you! Now, get back to work!</p>
 <p>Anniversary Team</p>
 Write-Host "Sending notification to $Name ($ToAddress)" -ForegroundColor Yellow

Leave a Reply

Your email address will not be published. Required fields are marked *