 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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
 