SOLVED

AD active users who have not changed passwords in last 6 months

%3CLINGO-SUB%20id%3D%22lingo-sub-2280503%22%20slang%3D%22en-US%22%3EAD%20active%20users%20who%20have%20not%20changed%20passwords%20in%20last%206%20months%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2280503%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20looking%20to%20see%20if%20someone%20can%20help%20or%20modify%20what%20is%20below%20to%20return%20me%20the%20value%20of%20%3CSTRONG%3Eactive%3C%2FSTRONG%3E%20users%20in%20AD%20that%20have%20not%20changed%20passwords%20in%20last%20x%20amount%20of%20months.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20found%20this%20in%20a%20microsoft%20document%20and%20works%20well%20however%20brings%20in%20all%20users.%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%24d%20%3D%20%5BDateTime%5D%3A%3AToday.AddDays(-180)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EGet-ADUser%20-Filter%20'(PasswordLastSet%20-lt%20%24d)%20-or%20(LastLogonTimestamp%20-lt%20%24d)'%20-Properties%20PasswordLastSet%2CLastLogonTimestamp%20%7C%20ft%20Name%2CPasswordLastSet%2C%40%7BN%3D%22LastLogonTimestamp%22%3BE%3D%7B%5Bdatetime%5D%3A%3AFromFileTime(%24_.LastLogonTimestamp)%7D%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EAny%20help%20is%20appreciated.%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2280503%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EActive%20Directory%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2281616%22%20slang%3D%22en-US%22%3ERe%3A%20AD%20active%20users%20who%20have%20not%20changed%20passwords%20in%20last%206%20months%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2281616%22%20slang%3D%22en-US%22%3EThank%20you%2C%20this%20worked!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2281177%22%20slang%3D%22en-US%22%3ERe%3A%20AD%20active%20users%20who%20have%20not%20changed%20passwords%20in%20last%206%20months%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2281177%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1021701%22%20target%3D%22_blank%22%3E%40dmk199%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%3C%2FP%3E%3CP%3EThis%20is%20a%20quick%20one.%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%24d%20%3D%20%5BDateTime%5D%3A%3AToday.AddDays(-180)%0A%0AGet-ADUser%20-Filter%20'((PasswordLastSet%20-lt%20%24d)%20-or%20(LastLogonTimestamp%20-lt%20%24d))%20-and%20((UserAccountControl%20-eq%20512)%20-or%20(UserAccountControl%20-eq%2066048))%20'%20-Properties%20PasswordLastSet%2CLastLogonTimestamp%2CUserAccountControl%20%7C%20ft%20Name%2CPasswordLastSet%2C%40%7BN%3D%22LastLogonTimestamp%22%3BE%3D%7B%5Bdatetime%5D%3A%3AFromFileTime(%24_.LastLogonTimestamp)%7D%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EThe%20Key%20is%20with%20an%20AD%20attribute%20named%20%3CSTRONG%3EUserAccountControl.%3C%2FSTRONG%3E%20if%20the%20value%20of%20this%20attribute%20was%20512%20this%20mean%20that%20the%20user%20is%20active%26nbsp%3B%3C%2FP%3E%3CP%3Eif%20the%20value%20was%2066048%20this%20mean%20that%20the%20user%20is%20active%20with%20password%20never%20expires.%3C%2FP%3E%3CP%3ETry%20it%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20this%20answer%20help%2C%20please%20click%20on%20Best%20Respone.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

I am looking to see if someone can help or modify what is below to return me the value of active users in AD that have not changed passwords in last x amount of months.

 

I found this in a microsoft document and works well however brings in all users. 

$d = [DateTime]::Today.AddDays(-180)

Get-ADUser -Filter '(PasswordLastSet -lt $d) -or (LastLogonTimestamp -lt $d)' -Properties PasswordLastSet,LastLogonTimestamp | ft Name,PasswordLastSet,@{N="LastLogonTimestamp";E={[datetime]::FromFileTime($_.LastLogonTimestamp)}}

 

Any help is appreciated. 

 

 

2 Replies
best response confirmed by dmk199 (Occasional Contributor)
Solution

@dmk199 

Hi

This is a quick one. 

$d = [DateTime]::Today.AddDays(-180)

Get-ADUser -Filter '((PasswordLastSet -lt $d) -or (LastLogonTimestamp -lt $d)) -and ((UserAccountControl -eq 512) -or (UserAccountControl -eq 66048)) ' -Properties PasswordLastSet,LastLogonTimestamp,UserAccountControl | ft Name,PasswordLastSet,@{N="LastLogonTimestamp";E={[datetime]::FromFileTime($_.LastLogonTimestamp)}}

The Key is with an AD attribute named UserAccountControl. if the value of this attribute was 512 this mean that the user is active 

if the value was 66048 this mean that the user is active with password never expires.

Try it

 

 

If this answer help, please click on Best Respone.

 

Thank you, this worked!