Skip to content

Instantly share code, notes, and snippets.

@Ethanb00
Created September 30, 2022 17:13
Show Gist options
  • Save Ethanb00/a0b4a2bc67a95fc0575b36fb31a04d7b to your computer and use it in GitHub Desktop.
Save Ethanb00/a0b4a2bc67a95fc0575b36fb31a04d7b to your computer and use it in GitHub Desktop.
Script to List Expired and Expiring Active Directory Passwords (90 days forward)
$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