# Email someone of choice a list of all user accounts (not passwords) that are about to expire in 3 days # Possibility to narrow down the search to one specific OU while ignoring one sub OU of it. # Be sure to adjust all CAPITAL wording for replacements specific to you as well as the mail/smtp settings at the bottom. Try { Import-Module ActiveDirectory -ErrorAction Stop } Catch { Write-Host "Unable to load Active Directory module, is RSAT installed?"; Break } $ExpiringUsers = Search-ADAccount -AccountExpiring -TimeSpan "3" -SearchBase "OU=YOURUSERSOU,DC=YOURCOMPANY,DC=COM" | Where-Object { $_.DistinguishedName -notlike "*OU=EXCLUDEDSUBOU,OU=YOURUSERSOU,DC=YOURCOMPANY,DC=COM*"} If ($ExpiringUsers) { $Header = @" "@ $Pre = "'YOURUSERS' OU User Accounts expiring in 3 Days (excluding the 'EXCLUDEDSUBOU'):" $Body = $ExpiringUsers | Select SamAccountName,Name,AccountExpirationDate | ConvertTo-HTML -PreContent $Pre -Head $Header | Out-String $SMTPSettings = @{ To = "YOURServiceDesk@YOURCOMPANY.com" From = "EUAccountCheckers@YOURCOMPANY.com" Subject = $Pre SMTPServer = "YourSMTPRelayServer" } Send-MailMessage @SMTPSettings -Body $Body -BodyAsHtml }