November 27th, 2014

PowerTip: Use PowerShell to Work with Active Directory Date Fields

Doctor Scripto
Scripter

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)

 

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.