Category filter
Scripts to create users on Windows devices
Some corporate devices might be used by more than one employee. As a result, an administrator might have to create separate user accounts on each device. Manually creating accounts on all the devices can be a tedious task. Hexnode lets admins deploy scripts to get the job done.
Batch script
Create user
1
net user "username" "password" /add
1 |
net user "username" "password" /add |
E.g., To create a user Josh,
Net user "Josh" "Josh123" /add
On deploying the above script, a new user account with username Josh
will be added to the device, and the user can log in to the account using the password Josh123
.
To create a user account with no password, do not provide any value for password in the above script.
E.g., Net user "Josh" "" /add
Change username
You can change the name of the created user account by running the script given below.
1 |
wmic useraccount where name='Administrator' rename 'NewName' |
Replace ‘Administrator’ with the current name of the user and ‘NewName’ with the new name of the user, respectively.
Change password
The following script can be used to change the password for the user account.
1 |
net user "Username" "NewPassword" |
Replace “Username” and “NewPassword” with your user’s name and required password.
Change account type to Standard
1 |
net localgroup Administrators "Account Name" /delete |
Replace “Account Name” with your user account name.
Change account type to Administrator
1 |
net localgroup Administrators "Account Name" /add |
Replace “Account Name” with your user account name.
PowerShell script
Create user
To create a user without a password, you can run the script given below.
1 |
New-LocalUser -Name "username" -NoPassword |
E.g. To create a user Josh without a password,
New-LocalUser –Name "Josh" -NoPassword
You can also create a user account with a password by running the script given below.
1 |
New-LocalUser "username" -Password "password" |
E.g. To create a user Josh with a password,
New-LocalUser "Josh" -Password "Josh123"
Change username
You can change the name of the created user account by running the script given below.
1 |
Rename-LocalUser -Name "Administrator" -NewName "New Name" |
Replace ‘Administrator’ with the current name of the user and ‘NewName’ with the new name of the user, respectively.
Change password
The following script can be used to change the password for the user account.
1 2 3 |
$SecurePassword = ConvertTo-SecureString "NewPassword" -AsPlainText -Force $UserAccount = Get-LocalUser -Name "Username" $UserAccount | Set-LocalUser -Password $SecurePassword |
Replace “Username” and “NewPassword” with your user’s name and required password.
Change account type to Standard
1 |
Remove-LocalGroupMember -Group "Administrators" -Member "Account Name" |
Replace “Account Name” with your user account name.
Change account type to Administrator
1 |
Add-LocalGroupMember -Group "Administrators" -Member "Account Name" |
Replace “Account Name” with your user account name.