Reputation: 1
Please do not confuse my question with Password Expire notification. Does anyone know powershell script that can be used to notify a User that their Active Directory User Account is about to expire in X amount of days? Thank you in advance for any help that can be provided.
Upvotes: 0
Views: 794
Reputation: 32180
The Search-ADAccount
command that is a part of the ActiveDirectory module is designed to search for this (as well as similar queries) already:
$30Days = New-TimeSpan -Days 30
$ExpiringAccounts = Search-ADAccount -AccountExpiring -TimeSpan $30Days -UsersOnly
You could then, for example, iterate over these users and combine it with Send-MailMessage
to send emails.
Upvotes: 4