Tuesday, September 29, 2020

Create local user using powershell script

 First of all, prepare the user list as below and save it as users.csv file


Create a powershell script with the following code


The scripts will first need to convert the password string from the csv file into a secureString. This is necessary for New-LocalUser cmdlet. After that, the script will set PasswordNeverExpires option as well as add those user into Administrators group.

I am using this script for my test setup which need a lot of dummy users. For production environment, you can actually create random password instead of specifying password in the users.csv file and set the "-ChangePasswordAtLogon $true" option. And obviously, you can also change the User group to "Users" group instead of "Administrators" group.

No comments: