Created
September 30, 2022 17:13
-
-
Save Ethanb00/a0b4a2bc67a95fc0575b36fb31a04d7b to your computer and use it in GitHub Desktop.
Script to List Expired and Expiring Active Directory Passwords (90 days forward)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$maxPasswordAge = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge.Days | |
$AdUsers = Get-ADUser -Filter {accountExpires -ne $false -and PasswordneverExpires -eq $false -and Enabled -eq $true} -Properties * | sort -Property name | |
foreach ($i in $AdUsers){ | |
$LastSet = $i.PasswordLastSet | |
$ExDate = $LastSet.addDays($maxPasswordAge) | |
if($ExDate -lt (Get-Date).AddDays(90) -and $ExDate -ge (Get-Date) ){ | |
$passExpireSoon = $passExpireSoon + $i.name + ", $ExDate`n" | |
}elseif($ExDate -lt (Get-Date)){ | |
$passExpired = $passExpired + $i.name + ", $ExDate`n" | |
} | |
} | |
Write-host "About to expire: `n$passExpireSoon" | |
Write-Host | |
Write-host "Password expired: `n$passExpired" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment