Created
August 15, 2018 12:05
-
-
Save PSingletary/3e6cba225c417a3d00c0af4faa69e35a to your computer and use it in GitHub Desktop.
Find out when your Password Expires (PowerShell Module) - Source: https://blogs.msdn.microsoft.com/adpowershell/2010/02/26/find-out-when-your-password-expires/
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
function Get-XADUserPasswordExpirationDate() { | |
Param ([Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true, HelpMessage="Identity of the Account")] | |
[Object] $accountIdentity) | |
PROCESS { | |
$accountObj = Get-ADUser $accountIdentity -properties PasswordExpired, PasswordNeverExpires, PasswordLastSet | |
if ($accountObj.PasswordExpired) { | |
echo ("Password of account: " + $accountObj.Name + " already expired!") | |
} else { | |
if ($accountObj.PasswordNeverExpires) { | |
echo ("Password of account: " + $accountObj.Name + " is set to never expires!") | |
} else { | |
$passwordSetDate = $accountObj.PasswordLastSet | |
if ($passwordSetDate -eq $null) { | |
echo ("Password of account: " + $accountObj.Name + " has never been set!") | |
} else { | |
$maxPasswordAgeTimeSpan = $null | |
$dfl = (get-addomain).DomainMode | |
if ($dfl -ge 3) { | |
## Greater than Windows2008 domain functional level | |
$accountFGPP = Get-ADUserResultantPasswordPolicy $accountObj | |
if ($accountFGPP -ne $null) { | |
$maxPasswordAgeTimeSpan = $accountFGPP.MaxPasswordAge | |
} else { | |
$maxPasswordAgeTimeSpan = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge | |
} | |
} else { | |
$maxPasswordAgeTimeSpan = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge | |
} | |
if ($maxPasswordAgeTimeSpan -eq $null -or $maxPasswordAgeTimeSpan.TotalMilliseconds -eq 0) { | |
echo ("MaxPasswordAge is not set for the domain or is set to zero!") | |
} else { | |
echo ("Password of account: " + $accountObj.Name + " expires on: " + ($passwordSetDate + $maxPasswordAgeTimeSpan)) | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment