Created
December 16, 2019 19:07
-
-
Save shinjijai/506e5966568c9c676434e77b5d44f881 to your computer and use it in GitHub Desktop.
Check ActiveDirectory user's password status
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
#Requires -Version 4.0 | |
#Requires -Module ActiveDirectory | |
<# | |
.SYNOPSIS | |
Returns information on the user(s) account status. | |
.DESCRIPTION | |
Connects to the Active Directory that you are close to and pulls information from it. | |
Which means that information about the user that are not sync between ActiveDirectory | |
will not be accurate. But information like Days since password was set, will be valid, no matter what. | |
#> | |
Import-Module ActiveDirectory -ErrorAction SilentlyContinue | |
do { | |
# Ask for the name of the user to search for | |
Clear-Host | |
$User = Read-Host "Please enter a name " | |
$User = "*$User*" | |
# Searches the AD to find any object that matches the criteria and then outputs | |
# the information with the Name, password status, and if the account is disable | |
$SelectParams = @( | |
"Name", | |
@{Name = "Password status"; Expression = {$_.LockedOut}}, | |
@{Name = "Enabled status"; Expression = {$_.Enabled}}, | |
@{Name = "Last logon"; Expression = {[DateTime]::FromFileTime($_.LastLogonTimeStamp)}}, | |
@{Name = "Last password set"; Expression = {(Get-Date($_.PasswordLastSet)).ToLocalTime()}}, | |
@{Name = "Last bad password"; Expression = {[DateTime]::FromFileTime($_.BadPasswordTime)}}, | |
@{Name = "Days since password was set"; Expression = { | |
New-TimeSpan -Start (Get-Date($_.PasswordLastSet)) -End (Get-Date) | Select-Object -ExpandProperty Days | |
}} | |
) | |
Get-ADUser -Filter {(SAMAccountName -like $User) -or (DisplayName -like $User)} -Properties * | Select-Object $SelectParams | Format-List | |
$SelSearch = Read-Host "Do another search for user(s) password status? (y/n)" | |
try { | |
$Ans = $SelSearch.Substring(0,1) | |
} catch { | |
Write-Host "Exiting..." | |
} | |
} while ($Ans -eq "y") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment