Configure the Days you want to be notified when Password of Users will expire,

You get a list of Users which Password will expire duirng the next days, you can easily change to do an Action for this Users.

We will read all active Users from AD which have e PW Expire Policy aplied, this User will be used for the Script.

Try an let my know if you like it

 

 

PowerShell
Edit|Remove
######################################################## 
#Name: GetPWExpireFromAD.ps1                           # 
#Creator: Michael Seidl aka Techguy                    # 
#CreationDate: 27.11.2013                              # 
#LastModified:27.11.2013                               # 
#Version: 1.0                                          # 
#Short Description:                                    # 
#Doc: http://www.techguy.at/tag/getpwexpirefromad/     # 
######################################################## 
#www.techguy.at                                        # 
#www.facebook.com/TechguyAT                            # 
#www.twitter.com/TechguyAT                             # 
#michael@techguy.at                                    # 
######################################################## 
 
 
#Import Active Directory Module 
Import-Module ActiveDirectory 
 
#Day of Span 
$Days="33" 
 
#Settings 
$Date=Get-Date -Format yy-MM-dd((Get-Date).adddays($Days)) 
$Users=Get-ADUser -filter {(Enabled -eq $True-and (PasswordNeverExpires -eq $False)} -Properties DisplayName, msDS-UserPasswordExpiryTimeComputed, Mail | Where-Object {$_.DisplayName -ne $null| Select Mail, DisplayName,@{Name="ExpiryDate";Expression={([datetime]::fromfiletime($_."msDS-UserPasswordExpiryTimeComputed")).DateTime}}  
 
#Magic 
foreach ($Entry in $Users) { 
    $EntryDate = Get-date($Entry.ExpiryDate) -Format yy-MM-dd 
    if ($EntryDate -lt $Date) { 
        Write-Host "Alarm: The User" $entry.DisplayName "with Mailaddress:" $Entry.Mail "will expire at" $EntryDate -ForegroundColor Red 
    } 
    else  
    { 
        Write-host "OK: The User" $entry.DisplayName "with Mailaddress:" $Entry.Mail "will expire at" $EntryDate -ForegroundColor green 
    } 
}