Help
Help

Reputation: 181

Windows Command To List Expired User Accounts Only

Using PowerShell, I would like to list user accounts that have expired only.

I've crafted the command below which lists all user accounts on my machine and also displays the account expires column:

get-localuser  | select Name, AccountExpires

Example output:

Name           AccountExpires
----           --------------
Administrator    
Guest           
test           09/05/2021 00:00:00

How do I only list expired accounts?

Upvotes: 0

Views: 954

Answers (1)

Steven
Steven

Reputation: 7057

I primarily work in a domain environment, but it looks like you can simply look at the AccountExpires property and compare it to the current date. Something like below may work:

$Now = Get-Date
Get-LocalUser  | Where-Object{ $_.AccountExpires -le $Now }

You can Select whatever you like after that.

Upvotes: 1

Related Questions