- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create a new local user in windows using PowerShell?
To create a new local user in the Windows operating system using PowerShell, we can use the New-LocalUser cmdlet. The below command will create the TestUser with no password.
New-LocalUser -Name TestUser -NoPassword
Output
Name Enabled Description ---- ------- ----------- TestUser True
TestUser account has been enabled here. To provide the password for the user, the password should be in the secure string format. We can pass the password as shown below.
$pass = "Admin@123" | ConvertTo-SecureString -AsPlainText -Force New-LocalUser -Name TestUser -Password $pass
The above commands will create the TestUser with the password. To add the password and account-related settings we can directly provide parameters but for ease, we will use the splatting method as shown below.
$Localuseraccount = @{ Name = 'TestUser' Password = ("Admin#123" | ConvertTo-SecureString -AsPlainText -Force) AccountNeverExpires = $true PasswordNeverExpires = $true Verbose = $true } New-LocalUser @Localuseraccount
The above command will create testuser with a password and set its property to Account Never Expires and Password Never Expires.
Advertisements