Reputation: 181
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
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