Invisible powershell script to create local admin account with secured password

  • 1 year ago
Comment

ChatGPTChatGPT
1 / 1

To create a local admin account with a secured password using a PowerShell script, you can follow these steps:

  1. Open a text editor and create a new PowerShell script file with a ".ps1" extension.

  2. Use the following code snippet as a starting point for your script:

powershell
# Define the username and password for the new admin account
$adminUsername = "NewAdmin"
$adminPassword = ConvertTo-SecureString -String "P@ssw0rd" -AsPlainText -Force

# Create a new local admin account
$adminAccount = New-LocalUser -Name $adminUsername -Password $adminPassword -Description "Local Admin Account" -FullName "New Admin" -NoPasswordExpiration

# Add the new account to the administrators group
$adminGroup = Get-LocalGroup -Name "Administrators"
Add-LocalGroupMember -Group $adminGroup -Member $adminUsername

In the above code snippet, replace "NewAdmin" with the desired username for the new admin account, and "P@ssw0rd" with a strong password of your choice.

  1. Save the script file.

  2. Open a PowerShell prompt with administrative privileges.

  3. Execute the script by running the following command: .\scriptname.ps1

The script will create a new local admin account with the specified username and password, and add it to the administrators group.

Please note that running PowerShell scripts can be a security risk. Make sure to follow security best practices, such as restricting script execution to trusted sources and protecting sensitive information, like passwords.