With the introduction of PowerShell 5.1 new commands for local user administration were introduced. I`m glad to hear that. I don`t like net user.
Discovering Local User Administration Commands
First, make sure your system is running PowerShell 5.1. Open PowerShell and run
(Get-Host).Version
The commands can be found by running
Get-Command -Module Microsoft.PowerShell.LocalAccounts
Users Last Logon Time
Back to topic. To find out all users, who have logged on in the last 10 days, run
Get-LocalUser | Where-Object {$_.Lastlogon -ge (Get-Date).AddDays(-10)} | Select-Object Name,Enabled,SID,Lastlogon | Format-List
To search for users, who have not logged on in the last 30 days, run
Get-LocalUser | Where-Object {$_.Lastlogon -le (Get-Date).AddDays(-30)} | Select-Object Name,Enabled,SID,Lastlogon | Format-List
Other examples
Creating users:
New-LocalUser -Name Peter -Password (ConvertTo-SecureString "Pa$$w0rd" -AsPlainText -Force)
Configuring the password never expires setting:
Set-LocalUser -Name Peter -PasswordNeverExpires $true -Description Brother
Further thoughts
For administering Active Directory accounts I recommend my article PowerShell: My top 10 commands for documenting and monitoring Active Directory
Categories: PowerShell
1 reply »