PowerTip: Use PowerShell to Work with Active Directory Date Fields

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)


Comments (1)

  1. AllenRich says:

    Nice post, thanks for sharing it.

Skip to main content