7,023 questions
Hello lalajee,
Take a look at the following article:
Regularly check for and remove inactive user accounts in Active Directory
$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)}}
Hope this helps.
If this is helpful please accept answer.