Michael Higashi
Michael Higashi

Reputation: 21

Check if Local User account exists and create it if it doesn't exist

I'm trying to write a command line script that will check if an local user account exists and create that account if it doesn't.

I have the two commands, but I want to put it together into a conditional check.

Command to check if the account exists.

Net user | find /i "Username"

Here's the command to create the account.

NET USER Username {Password}  /EXPIRES: NEVER /ADD

Also, I'm having problems with the /Expires switch working. When I check the account's settings it doesn't have "Password never expires" as checked.

Upvotes: 2

Views: 4404

Answers (1)

Steve
Steve

Reputation: 11

The /Expires switch is for the account, not the password. Try running this from PowerShell.

$user = "User3"
NET USER $user "Good1!PW" /Add 
Set-LocalUser -Name $user -PasswordNeverExpires $true -UserMayChangePassword $false

Upvotes: 1

Related Questions