How to Convert pwdLastSet to a Date in PowerShell

Convert pwdLastSet to a date in PowerShell

To convert pwdLastSet to a date in PowerShell, pass the number to [datetime]::FromFileTimeUtc(). pwdLastSet is a Windows FILETIME, the count of 100-nanosecond ticks since January 1, 1601 in UTC: Below I convert it to Eastern time, handle the special 0 value, turn a date back into a FILETIME for LDAP filters and build a password … Read more

Find Users With PwdLastSet Older Than 90 Days (PowerShell)

Find users with PwdLastSet older than 90 days using PowerShell

To find users whose PwdLastSet is older than 90 days, filter Get-ADUser on PasswordLastSet, the converted version of the pwdLastSet attribute: Below I test the filter on sample accounts, handle users who must change their password, build an LDAP filter for big domains and export an audit report. My test PC isn’t on a domain, … Read more

How to Create a Folder with the Current Date Using PowerShell

Create a folder with the current date in PowerShell

To create a folder with the current date in PowerShell, format today’s date as text and pass it to New-Item with -ItemType Directory: Output: I used a fixed date so the output doesn’t change. In a real script, use $today = Get-Date. Every example ran in PowerShell 7.6 and Windows PowerShell 5.1, with the same … Read more

How to Add a Date to a File Name Using PowerShell

Add date to file name in PowerShell

To add a date to a filename in PowerShell, format the date as text with (Get-Date).ToString(‘yyyy-MM-dd’) or Get-Date -Format ‘yyyy-MM-dd’, then put it inside the name: Output: I used a fixed date so the output doesn’t change. In a real script, use $now = Get-Date. Every example here ran in PowerShell 7.6 and Windows PowerShell … Read more

PowerShell Date Comparison: Compare Dates the Right Way

PowerShell date comparison

To compare dates in PowerShell, make sure both sides are [datetime] values, then use -lt, -gt and -eq. Subtracting one date from another tells you how far apart they are: Output: Earlier means smaller, so -lt reads as “before” and -gt as “after.” I ran every example in PowerShell 7.6 and Windows PowerShell 5.1, with … Read more

How to Sort Files by Date in PowerShell (Modified, Created, Newest)

Sort files by date in PowerShell

To sort files by date in PowerShell, pipe Get-ChildItem to Sort-Object LastWriteTime. Add -Descending to put the newest file first: LastWriteTime is the date modified you see in File Explorer. I set up a test folder with known dates and ran every example in PowerShell 7 and Windows PowerShell 5.1. Sort files by date modified … Read more

PowerShell Get-Date Format ISO 8601 (o, s, u, UTC and Parsing)

PowerShell Get-Date format ISO 8601

To format a date as ISO 8601 in PowerShell, use Get-Date with the round-trip format specifier o. It returns a string with the date, the time to seven decimal places and the UTC offset: On a PC set to Eastern time, that looks like 2026-10-26T09:30:15.2500000-04:00. Use Get-Date -Format s for a shorter stamp without fractions … Read more

PowerShell Get-Date UTC: Get, Format and Convert UTC Time

PowerShell Get-Date UTC examples

Need the current time in UTC? In PowerShell 7.1 and later, Get-Date -AsUTC returns it directly. Windows PowerShell 5.1 doesn’t have that switch, so use [datetime]::UtcNow there, which works in every version: Both return a DateTime whose Kind is Utc. Below I’ll format UTC values, convert them to and from US time zones, parse UTC … Read more