Created
July 31, 2017 13:49
-
-
Save spy86/800a947077d11e684530e770ffeff84a to your computer and use it in GitHub Desktop.
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
#Check if the account exists. | |
If($Results.Count -eq 0) | |
{ | |
Write-Warning "The SamAccountName '$UserName' cannot find. Please make sure that it exists." | |
} | |
Else | |
{ | |
Foreach($Result in $Results) | |
{ | |
$DistinguishedName = $Result.Properties.Item("DistinguishedName") | |
$LastLogonTimeStamp = $Result.Properties.Item("LastLogonTimeStamp") | |
If ($LastLogonTimeStamp.Count -eq 0) | |
{ | |
$Time = [DateTime]0 | |
} | |
Else | |
{ | |
$Time = [DateTime]$LastLogonTimeStamp.Item(0) | |
} | |
If ($LastLogonTimeStamp -eq 0) | |
{ | |
$LastLogon = $Time.AddYears(1600) | |
} | |
Else | |
{ | |
$LastLogon = $Time.AddYears(1600).ToLocalTime() | |
} | |
#Output in comma delimited format. | |
$Hash = @{ | |
SamAccountName = $UserName | |
LastLogonTimeStamp = $(If($LastLogon -match "12/31/1600") | |
{ | |
"Never Logon" | |
} | |
Else | |
{ | |
$LastLogon | |
}) | |
} | |
$Objs = New-Object -TypeName PSObject -Property $Hash | |
$Objs | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment