Created
April 3, 2018 17:18
-
-
Save chelming/748ea411c542b02a83d4987788322a3b to your computer and use it in GitHub Desktop.
Using powershell to change the password for a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Invoke-PrinterPost ($WebSession, $Printer, $Body) { Invoke-RestMethod -WebSession $WebSession -Uri "https://$Printer.example.com/userpost/xerox.set" -Body $Body -Method Post } | |
$CurrentPassword = "Pr1nt3rzBl0w" | |
$NewPassword = "I<3PowerShell" | |
$PrintServer = "print.example.com" | |
$Printers = Get-Printer -ComputerName $PrintServer | Where-Object { $_.DriverName -like "Xerox*" } | Select -ExpandProperty Name | |
Foreach ($Printer in $Printers) { | |
$CSRFToken = (Invoke-WebRequest -SessionVariable Xerox -Uri "https://$printer.example.com/auth/config/new_password.php").Forms.Fields.CSRFToken | |
$LoginBody = "_fun_function=HTTP_Authenticate_fn&NextPage=/properties/authentication/luidLogin.php&webUsername=admin&webPassword=$CurrentPassword&frmaltDomain=default&CSRFToken=$CSRFToken" | |
$rm = Invoke-PrinterPost $Xerox $Printer $LoginBody | |
$PasswordBody = "_fun_function=HTTP_Set_Config_Attrib_fn&authentication.passwordToSet=$NewPassword&authentication.adminPasswordSet=TRUE&userID=admin&oldPassword=$CurrentPassword&_fun_function=HTTP_SetUIDPassword_fn&CSRFToken=$CSRFToken&NextPage=%2Fauth%2Fconfig%2Fnew_password.php" | |
$rm = Invoke-PrinterPost $Xerox $Printer $PasswordBody | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment