-1

I am attempting to write a batch script that adds new users to a machine using user prompts to get the information. I am at the point where the user gets created correctly, but the "Full Name" and "Description" fields don't populate, no matter what I try. I can't seem to get it to pass the %fullname% variable into either the net user command or the wmic command. If I just type quoted text into either spot it adds the information properly. Also if there's a better way to do echos like that it would be appreciated, takes up too many lines IMO. :)

:User

echo.
echo Please Input Username...
echo.

set /p username=Username:

echo.
echo Please Confirm Username... 
echo.

set /p confirm=Username:

if '%username%' == '%confirm%' (
echo.
echo Please Input User Full Name...
echo.

set /p fullname=Full Name:

echo.
echo Please Input User Description...
echo.

set /p description=Description:

echo Creating %username%...
net user %username% * /add /active:yes /fullname:%fullname% /comment:%description% /passwordchg:no /expires:never
wmic useraccount where "Name='%username%'" set PasswordExpires=FALSE
wmic useraccount where "Name='%username%'" set FullName=%fullname%

This script creates the user just fine, but the fullname and comment fields are blank.

user3470424
  • 1
  • 1
  • 1
  • An interesting sounding title leads to a notable question but has a trivial cause of missing quotes. –  Aug 22 '19 at 06:34

1 Answers1

0

Problem solved. Apparently the parentheses for my if statement were messing everything up. The fullname and description variables were blank for whatever reason. I guess you can't do a set inside an if statement?

No matter, changing to this has solved the problem and it works perfectly now.

:User

echo.
echo Please Input Username...
echo.

set /p username=Username:

echo.
echo Please Confirm Username... 
echo.

set /p confirm=Username:

if '%username%' == '%confirm%' goto User1

goto User

:User1
echo.
echo Please Input User Full Name...
echo.

set /p fullname=Full Name:

echo.
echo Please Input User Description...
echo.

set /p description=Description:

pause
echo Creating %username%...
net user %username% * /add /active:yes /fullname:"%fullname%" /comment:"%description%" /passwordchg:no /expires:never
wmic useraccount where "Name='%username%'" set PasswordExpires=FALSE
user3470424
  • 1
  • 1
  • 1