Conditions:
You need to send mail message to exchange mail group of recipients notification about someone birthday, which is stored in AD as string field, script will send by schedule such notification, 1 birthday - 1 notification, with a bit work may be array (1 for few birthdays), and more perfect view.
$bday = get-aduser -Filter {(ObjectClass -eq "user") -and (DRAttribute -like "*") -and (mail -like "*")} -SearchScope Subtree -SearchBase "OU=MyCompany,DC=MyDomain,DC=local" -Properties * | select DRAttribute,name,mail
foreach($row in $bday.DRAttribute)
{
$bdate = [datetime]::ParseExact($row,"dd.MM.yyyy”,$null)
$compare = (get-date -format M) -eq (get-date $bdate -format M)
if($compare -eq "True") {
$bdayPerson = get-aduser -Filter {(ObjectClass -eq "user") -and (DRAttribute -like $row) -and (mail -like "*")} -SearchScope Subtree -SearchBase "OU=MyCompany,DC=MyDomain,DC=local" -Properties * | select name
$random = ($a = "penguins.jpg","Desert.jpg","Jellyfish.jpg","lighthouse.jpg","tulips.jpg" ) | Get-Random
Send-MailMessage -To recepient@mydomain.com -Subject birthday -Body "<p>Happy Birthday, dear $bdayPerson! <br/><html><body><img src=$random /></p></body></html>"-smtpserver smtp.MyDomain.local -from sender@mydomain.com -Attachments "C:\spshablon\pictures\$random" -BodyAsHtml
}
}
You need to send mail message to exchange mail group of recipients notification about someone birthday, which is stored in AD as string field, script will send by schedule such notification, 1 birthday - 1 notification, with a bit work may be array (1 for few birthdays), and more perfect view.
$bday = get-aduser -Filter {(ObjectClass -eq "user") -and (DRAttribute -like "*") -and (mail -like "*")} -SearchScope Subtree -SearchBase "OU=MyCompany,DC=MyDomain,DC=local" -Properties * | select DRAttribute,name,mail
foreach($row in $bday.DRAttribute)
{
$bdate = [datetime]::ParseExact($row,"dd.MM.yyyy”,$null)
$compare = (get-date -format M) -eq (get-date $bdate -format M)
if($compare -eq "True") {
$bdayPerson = get-aduser -Filter {(ObjectClass -eq "user") -and (DRAttribute -like $row) -and (mail -like "*")} -SearchScope Subtree -SearchBase "OU=MyCompany,DC=MyDomain,DC=local" -Properties * | select name
$random = ($a = "penguins.jpg","Desert.jpg","Jellyfish.jpg","lighthouse.jpg","tulips.jpg" ) | Get-Random
Send-MailMessage -To recepient@mydomain.com -Subject birthday -Body "<p>Happy Birthday, dear $bdayPerson! <br/><html><body><img src=$random /></p></body></html>"-smtpserver smtp.MyDomain.local -from sender@mydomain.com -Attachments "C:\spshablon\pictures\$random" -BodyAsHtml
}
}
No comments:
Post a Comment