Set administrator password via batch file

Emil Mammadli 21 Reputation points
2022-03-28T19:32:59.867+00:00

Hello everyone,

I want to change administrator password via batch file or via ps1 file. But I want 2 important things:

  1. not show new password via message box;
  2. nobody read this batch file.

Please help me. Thanks.

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
11,159 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. cthivierge 4,036 Reputation points
    2022-03-28T20:05:58.667+00:00

    Where the password will come from ?
    Someone will type it manually ?

    If so,

    $Password = Read-Host -AsSecureString
    $UserAccount = Get-LocalUser -Name "User02"
    $UserAccount | Set-LocalUser -Password $Password

    For the file, if you want to restrict people from reading it, juste remove Users group from the NTFS permissions and only keep the user that will run the batch to be able to read the file.


  2. Thameur-BOURBITA 17,666 Reputation points
    2022-03-29T09:38:05.38+00:00

    Hi,

    I recommend you to avoid using script to change the local administrator account. Using the script you cannot ensure that the password is different on each server.

    I recommend you to deploy LAPS Local Administrator Password Solution. This solution is free and let you save the password in secure location : a protected attribute in active directory. To have more details about this solution , you can read the following articles:
    Microsoft LAPS usage

    Local Administrator Password Solution

    Please don't forget to mark helpful reply as answer

    0 comments No comments