Reputation: 17
I am looking a single line CMD command to check if local user exists & create if it doesn't exist.
I am aware about command to create a user:
"net user UserName Password /ADD"
As well as for checking if the user exists or not:
"net user | find /i UserName"
Though trying to see if there is a way to join these 2 commands to yield the desired result.
Any guidance would be greatly appreciated.
Upvotes: 0
Views: 1835
Reputation: 16256
How about using a condition based on whether the user exists?
SET "THEUSER=username"
NET USER "%THEUSER%" 1>NUL 2>&1 || NET USER "%THEUSER%" Password /ADD
Upvotes: 2