David Williams Technical


Endpoint Management & Deployment – MDM Management – Scripting – Cyber Security Engineering – Application Configuration & Deployment

PowerShell Script to Create a New User

Here’s an example of a PowerShell script that can be used to install a new user:


Define the user details (Parameters)

$Username = “newuser”
$Password = ConvertTo-SecureString “P@ssw0rd” -AsPlainText -Force
$FullName = “New User”
$Description = “This is a new user account.”

Create a new user

New-LocalUser -Name $Username -Password $Password -FullName $FullName -Description $Description -NoPasswordExpiration

Add the user to a specific group (optional)

$GroupName = “Administrators”
Add-LocalGroupMember -Group $GroupName -Member $Username

Display the user details

$User = Get-LocalUser -Name $Username
Write-Host “New user created:”
Write-Host “Username: $($User.Name)”
Write-Host “Full Name: $($User.FullName)”
Write-Host “Description: $($User.Description)”


In this script, we define the details for the new user, such as the username, password, full name, and description. You can modify these values according to your requirements. The New-LocalUser cmdlet is used to create a new local user account with the provided details. The -NoPasswordExpiration parameter ensures that the password doesn’t expire.

Optionally, you can add the new user to a specific group using the Add-LocalGroupMember cmdlet. In the example, the user is added to the “Administrators” group, but you can change the value of $GroupName to the desired group name.

Finally, the script retrieves the user details using the Get-LocalUser cmdlet and displays them on the console.

Please note that running PowerShell scripts can have security implications, so make sure to understand and validate the script before executing it. Also, ensure that you have appropriate permissions to create new users and add them to groups!!