Script that will send email based on data in CSV (expired secrets/certs)

Viewed 28

I have a CSV file with the headers listed in the below image. I am essentially trying to send an individual email to each owner ( in column J ) notifying them that "Application Name" ( in column A ) with ApplicationID ( in column B ) has been expired for X amount of months (in column I ). However, if possible, there are duplicate owners in column J that i would like to have grouped together.

example output:

From: MyEmail@org.com

To: UserEmail@org.com

Subject: Expired App Registration

Good Morning,

In regards to Application and with ApplicationID <987> and <123>, you are listed as the owner. These secrets have been expired for <#> and <#> amount of days respectively. Please advise if still being used or can be removed. Thanks!

This is all that I have so far:

$From = "MyEmail@org.com"
$To = "UserEmail@org.com"
$Cc = "BossEmail@org.com"
$Attachment = "C:\Users\<>\Desktop\AllExpired.csv"
$Subject = "Expired App Registration"
$Body = 

 Good Morning, In regards to Application <xyz> and <abc> with ApplicationID <987> and <123>, 
 you are listed as the owner. These secrets have been expired for <#> and <#> amount of days 
 respectively. Please advise if still being used or can be removed. Thanks! 
$SMTPServer = "blank.org.com"
$SMTPPort = "#"
Send-MailMessage -From $From -to $To -Cc $Cc -Subject $Subject `
-Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl `
-Credential (Get-Credential) -Attachments $Attachment
0 Answers
Related