Introduction
In system administration, you may need to create new administrator accounts efficiently and securely. This guide demonstrates how to create a Windows admin account using PowerShell.
The Script
Here’s a PowerShell script that creates a new administrator account with a secure password prompt:
# Prompt for password securely
$Password = Read-Host -AsSecureString "Enter password for admin"
# Create new local user
New-LocalUser -Name "<admin name>" -Password $Password -FullName "Admin User" -Description "Administrator account" -AccountNeverExpires
# Add user to administrators group
Add-LocalGroupMember -Group "Administrators" -Member "<admin name>"
Write-Host "User has been created and added to Administrators group"
How to Use the Script
- Open PowerShell as Administrator
- Right-click on PowerShell
- Select “Run as Administrator”
- Run the Script
- Copy the script above
- Replace
<admin name>
with your desired username - Paste it into your PowerShell window
- Press Enter to execute
- Enter Password
- When prompted, type the desired password
- The password input will be hidden for security
What the Script Does
The script performs three main actions:
- Creates a secure password prompt
- Creates a new local user account
- Adds the new account to the Administrators group
Security Considerations
Remember to:
- Use a strong password
- Run PowerShell with administrative privileges
- Store the script securely
- Change the default password regularly
Customization Options
You can modify the script by:
- Customizing the username
- Adding additional user properties
- Modifying the account description
- Adding more group memberships
Conclusion
This PowerShell script provides a quick and secure way to create a new administrator account on Windows systems. Modify it according to your needs and security requirements.
Note: Always follow your organization‘s security policies when creating new administrator accounts.