Код: Выделить всё
# File containing the list of servers
$ServerList = "C:\Users\seamless.aman\Desktop\server-list.txt"
# Credentials
$Username = "seamless.aman"
$CurrentPassword = "old_pass"
$NewPassword = "new_pass"
# Path to plink.exe
$PlinkPath = "C:\Program Files\PuTTY\plink.exe"
# Loop through each server
foreach ($Server in Get-Content $ServerList) {
Write-Host "Connecting to $Server..." -ForegroundColor Cyan
try {
# Temporary command file
$CommandFile = "C:\Temp\command-$Server.txt"
"echo -e `"$CurrentPassword`n$NewPassword`n$NewPassword`" | passwd $Username" | Set-Content $CommandFile
# Execute plink with -m
& $PlinkPath -ssh -v -l $Username -pw $CurrentPassword $Server -m $CommandFile
Write-Host "Password changed successfully on $Server." -ForegroundColor Green
} catch {
Write-Host "Failed to change password on $Server: $($_.Exception.Message)" -ForegroundColor Red
}
}
Код: Выделить всё
PS C:\Users\seamless.aman\Desktop> .\change-password.ps1
At C:\Users\seamless.aman\Desktop\change-password.ps1:28 char:50
+ Write-Host "Failed to change password on $Server: $($_.Except ...
+ ~~~~~~~~
Variable reference is not valid. ':' was not followed by a valid variable name character. Consider using ${} to delimit the name.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : InvalidVariableReferenceWithDrive
Подробнее здесь: https://stackoverflow.com/questions/791 ... sing-plink