| Add-PSSnapin Quest.ActiveRoles.ADManagement |
| get-qaduser -sizelimit 0 | where-object {$_.Email -ne $null -and $_.AccountIsDisabled -eq $false -and $_.AccountIsExpired -eq $false -and $_.PasswordNeverExpires -eq $false -and $_.AllMemberOf -notcontains "<DN of Group to Exclude>"} | foreach{ |
| $PasswordAgeMax = $null |
| $PasswordAgeMax = (Get-QADPasswordSettingsObject (Get-QADUser -Identity $_ -DontUseDefaultIncludedProperties -IncludedProperties 'msDS-ResultantPso' ).'msDS-ResultantPso' ).'msDS-MaximumPasswordAge'.Days |
| $PasswordAge = $PasswordAgeMax - ((Get-QADUser -Identity $_ ).passwordage.days) |
| $PasswordAge = [int]$PasswordAge |
| if ($PasswordAge -ne $null -and ($PasswordAge -eq 30 -or ($PasswordAge -le 15 -and $PasswordAge -gt 0))){ |
| $EmailFrom = "helpdesk@somedomain.com" |
| $EmailTo = (get-qaduser -identity $_).'Email' |
| $EmailFirstN = (get-qaduser -identity $_).'FirstName' |
| $EmailUserN = (get-qaduser -identity $_).'NTAccountName' |
| $Subject = "Technology Req.: Password Expires in $PasswordAge Days" |
| |
| $TextBody = "<Your Corporation Header> |
| Department of Technology |
| Password Change Request/Instructions |
| |
| $EmailFirstN, your password associated with the <SOMEDOMAIN> network will expire in $PasswordAge days. |
| Please review the attached document for instructions how to change your |
| network password associated with your ""$EmailUserN"" user account. |
| |
| If you should have any questions about the attached instructions or discover |
| any difficulties with any of the procedures, please contact helpdesk at: |
| - x1234 |
| - helpdesk@somedomain.com" |
| |
| $HTMLBody = "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN""> |
| <HTML><HEAD><META http-equiv=Content-Type content=""text/html; charset=iso-8859-1""> |
| </HEAD><BODY><DIV><FONT face=Arial color=#000000 size=2> |
| <Your Corporation Header><BR> |
| Department of Technology<BR> |
| <i>Password Change Request/Instructions</i><BR><BR> |
| |
| $EmailFirstN, your password associated with the <SOMEDOMAIN> network will expire in <b><u>$PasswordAge days</u></b>.<BR> |
| Please review the attached document for instructions how to change your<BR> |
| network password associated with your ""<b>$EmailUserN</b>"" user account.<BR><BR> |
| |
| If you should have any questions about the attached instructions or discover<BR> |
| any difficulties with any of the procedures, please contact helpdesk at:<BR> |
| - x1234<BR> |
| - helpdesk@somedomain.com |
| </FONT></DIV></BODY></HTML>" |
| |
| $SMTPMessage = New-Object System.Net.Mail.MailMessage $EmailFrom, $EmailTo, $Subject, $TextBody |
| |
| $Attachment = New-Object Net.Mail.Attachment("./How to Change Your Password Documentation.pdf") |
| $SMTPMessage.Attachments.Add($Attachment) |
| |
| $MIMEType = New-Object System.Net.Mime.ContentType("text/html") |
| $Alternate = [Net.Mail.AlternateView]::CreateAlternateViewFromString($HTMLBody, $MIMEType) |
| $SMTPMessage.AlternateViews.Add($Alternate) |
| |
| $SMTPServer = "smtp.somedomain.com" |
| $SMTP = New-Object System.Net.Mail.SMTPClient $SMTPServer |
| $SMTP.Send($SMTPMessage) |
| $_ |
| } |
| } |