Last active
August 29, 2015 14:18
-
-
Save scottames/dd340df226b985db8aa5 to your computer and use it in GitHub Desktop.
Get AD Password Expiration information
This file contains 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
### Get-PWDSet - Get password change and expiration information for given user | |
function Get-PWDSet{ | |
param([parameter(Mandatory=$true,Valuefrompipeline=$true)][string]$user) | |
$use = get-aduser $user -properties passwordlastset,passwordneverexpires | |
if($use.passwordneverexpires -eq $true){ | |
write-host $user "last set their password on " $use.passwordlastset " this account has a non-expiring password" -foregroundcolor yellow | |
$d1 = $use.passwordlastset | |
$d2 = get-date | |
if($d1 -gt $d2){ $diff = $d1 - $d2 } | |
elseif($d1 -lt $d2){ $diff = $d2 - $d1 } | |
else{ $diff = "equal dates" } | |
if($diff -gt "180"){ Write-Host "Maybe you should change the password as it is " $diff.days "old" -foregroundcolor red } | |
} | |
else{ | |
$til = (([datetime]::FromFileTime((get-aduser $user -properties "msDS-UserPasswordExpiryTimeComputed")."msDS-UserPasswordExpiryTimecomputed"))-(get-date)).days | |
if($til -lt "5"){ write-host $user "last set their password on " $use.passwordlastset "it will expire again in " $til "days" -foregroundcolor yellow } | |
else{ write-host $user "last set their password on " $use.passwordlastset "it will expire again in " $til "days" -foregroundcolor green } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment