question

emilemilmammadli-6480 avatar image
0 Votes"
emilemilmammadli-6480 asked Thameur-BOURBITA edited

Set administrator password via batch file

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

cthivierge avatar image
0 Votes"
cthivierge answered emilemilmammadli-6480 edited

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.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I want to type username and password in the script and anyone click this script automatically change administrator password. Automatically confirmation. Not ask me yes or no. Nobody see administrator's password and nobody can change this script. Can I explain?

0 Votes 0 ·
Thameur-BOURBITA avatar image
0 Votes"
Thameur-BOURBITA answered Thameur-BOURBITA edited

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.