PowerTip: Use PowerShell to Work with Active Directory Date Fields

Doctor Scripto

Summary: Use Windows PowerShell to work with Active Directory date fields.

Hey, Scripting Guy! Question How can I Use Windows PowerShell to work with date fields in Active Directory?

Hey, Scripting Guy! Answer Try the following techniques:

# Password last set within the last 30 days?

$pwdLastSet = Get-ADUser Administrator -Properties pwdLastSet |

     Select-Object -ExpandProperty pwdLastSet

# Option A

$pwdLastSet -gt (Get-Date).AddDays(-30).ToFileTimeUTC()

# Option B

[datetime]::fromFileTimeUTC($pwdLastSet) -gt (Get-Date).AddDays(-30)



Discussion is closed.

Feedback usabilla icon