Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spy86/800a947077d11e684530e770ffeff84a to your computer and use it in GitHub Desktop.
Save spy86/800a947077d11e684530e770ffeff84a to your computer and use it in GitHub Desktop.
#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