批量修改远程windows服务器密码

@echo off

setlocal enabledelayedexpansion

set username=<username>
set password=<password>
set newpassword=<newpassword>

for /f "tokens=*" %%a in (serverlist.txt) do (
  net use \\%%a\ipc$ /user:%username% %password%
  net user %username% %newpassword% /domain
  net use \\%%a\ipc$ /delete
)

echo All done!

请注意,你需要替换<username>,<password>和<newpassword> 为实际的用户名、当前密码和新密码。

serverlist.txt为需要修改的远程服务器IP列表

PowerShell可以这么写:

$username = "<username>"
$password = "<password>" | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($username, $password)
$newpassword = "<newpassword>" | ConvertTo-SecureString -AsPlainText -Force

Get-Content serverlist.txt | ForEach-Object {
    $computer = "\\$_"
    Invoke-Command -ComputerName $computer -Credential $credential -ScriptBlock {
        $user = [adsi]"WinNT://./$env:username,user"
        $user.SetPassword($env:newpassword)
    }
}

Write-Output "All done!"
网关安装pwsh,创建自动计划即可修改Windows服务器密码,你需要替换<username>,<password>和<newpassword> 为实际的用户名、当前密码和新密码。server为服务器IP:

#!/bin/bash

username="<username>"
password="<password>"
newpassword="<newpassword>"
server="server"

pwsh -Command "
  $username = '$username'
  $password = '$password' | ConvertTo-SecureString -AsPlainText -Force
  $credential = New-Object System.Management.Automation.PSCredential($username, $password)
  $newpassword = '$newpassword' | ConvertTo-SecureString -AsPlainText -Force
  Invoke-Command -ComputerName \\$server -Credential $credential -ScriptBlock {
    $user = [adsi]"WinNT://./$env:username,user"
    $user.SetPassword($env:newpassword)
  }
"

echo "All done!"