Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Creating local user accounts on Windows systems is a common task for systems administrators who need to manage access to machines. The New-LocalUser
cmdlet in PowerShell is a powerful tool that allows you to create local user accounts efficiently. This article will guide you through the process of using New-LocalUser
to create new local users on a Windows machine.
New-LocalUser
The New-LocalUser
cmdlet is part of the Microsoft.PowerShell.LocalAccounts module, which is included in Windows 10 and Windows Server 2016 and later. This cmdlet allows you to create a local user account on a Windows system. It is a straightforward way to automate the creation of user accounts without needing to navigate through the graphical user interface.
To create a simple local user account with the username "newuser" and a password, you can use the following PowerShell command:
$Password = Read-Host -AsSecureString "Enter the password for the new user"
New-LocalUser -Name "newuser" -Password $Password -FullName "New User" -Description "This is a new local user account"
This command will prompt you to enter a password for the new user. The password is stored as a secure string to ensure it is not exposed in plain text.
If you want the password for the new user to expire, you can add the -PasswordNeverExpires
parameter set to $false
:
$Password = Read-Host -AsSecureString "Enter the password for the new user"
New-LocalUser -Name "newuser" -Password $Password -FullName "New User" -Description "This is a new local user account" -PasswordNeverExpires $false
This ensures that the user will be prompted to change their password after a certain period, enhancing security.
To create a local user and immediately add them to a local group, such as the "Administrators" group, you can use the following commands:
$Password = Read-Host -AsSecureString "Enter the password for the new user"
New-LocalUser -Name "newadmin" -Password $Password -FullName "New Admin User" -Description "This is a new admin user account"
Add-LocalGroupMember -Group "Administrators" -Member "newadmin"
This command sequence creates a new user and adds them to the "Administrators" group, granting them elevated privileges.
The New-LocalUser
cmdlet is a versatile tool for creating local user accounts on Windows systems. By leveraging PowerShell, administrators can automate user management tasks, improving efficiency and consistency across systems. Whether you need to create a single user or automate the creation of multiple accounts, New-LocalUser
provides a straightforward and effective solution.