Skip to content

Instantly share code, notes, and snippets.

@chelming
Created April 3, 2018 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chelming/748ea411c542b02a83d4987788322a3b to your computer and use it in GitHub Desktop.
Save chelming/748ea411c542b02a83d4987788322a3b to your computer and use it in GitHub Desktop.
Using powershell to change the password for a
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