![]() ![]() For the date we will need to use a PowerShell DateTime object: $date = Get-Date -Year 2022 -Month 06 -Day 10 Setting the Expired Dateīy default, the new user account won’t expire, but with the New-LocalUser cmdlet, we can set an expiration date for the account. You could save this into a ps1 file and simply run it in an elevated PowerShell session. New-LocalUser -Name "$username" -Password $password -FullName "$username" -Description "Lazy Test user" $password = ConvertTo-SecureString "LazyAdminPwd123!" -AsPlainText -Force # Super strong plane text password here (yes this isn't secure at all) ![]() But keep in mind, anyone who opens the script is able to read the password! # Username and Password If you run the script remotely or under your own supervision then you could write the password inside a PowerShell script and convert it to a secure string. This is also the challenge with creating local users, most of the time you want to supply the password in a secure way. Providing the PasswordĪs you can see this won’t allow you to run the script autonomous, because you will need to enter a password. This small PowerShell script will require you to first enter the password, after which the user is created with the given password. New-LocalUser -Name "LazyUser" -Password $password -FullName "Lazy User" -Description "Test user" PowerShell New localuser ![]() So to quickly create a local user account with PowerShell we can do the following: $password = Read-Host -AsSecureString Login name of the account – max 20 characters There are also a couple of other useful parameters that we can use: Parameter We have the option to set a password for the account or create an account without a password. To create a new local user we are going to use the New-LocalUser cmdlet in PowerShell. Complete Script for new localuser in PowerShell.Making user member of a group with Add-LocalGroupMember. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |