Asked a few colleagues, and was supplied with these 2 choices:
############## script start ##############
############## script start ##############
$CookieContainer = New-Object System.Net.CookieContainer
function SendGET([string]$url)
{
[net.httpWebRequest] $req = [net.webRequest]::create($url);
$req.Method = "GET";
$req.Accept = "text/html";
$req.CookieContainer = $CookieContainer;
[net.httpWebResponse] $res = $req.getResponse();
$resst = $res.getResponseStream();
$sr = new-object IO.StreamReader($resst);
$result = $sr.ReadToEnd();
return $result;
}
function SendPOST([string]$url, [string]$data)
{
$buffer = [text.encoding]::ascii.getbytes($data)
[net.httpWebRequest] $req = [net.webRequest]::create($url)
$req.method = "POST"
$req.ContentType = "application/x-www-form-urlencoded"
$req.ContentLength = $buffer.length
$req.KeepAlive = $true
$req.CookieContainer = $CookieContainer
$reqst = $req.getRequestStream()
$reqst.write($buffer, 0, $buffer.length)
$reqst.flush()
$reqst.close()
[net.httpWebResponse] $res = $req.getResponse()
$resst = $res.getResponseStream()
$sr = new-object IO.StreamReader($resst)
$result = $sr.ReadToEnd()
$res.close()
return $result;
}
# Request to get session id
$x = SendGET ("http://10.10.10.1/properties/authentication/login.php");
# Post login to get new session id
$x = SendPOST ("http://10.10.10.1/userpost/xerox.set") ("_fun_function=HTTP_Authenticate_fn&NextPage=%2Fproperties%2Fauthentication%2FluidLogin.php&webUsername=admin&webPassword=password&frmaltDomain=default");
# Post reboot command with loggedin session id
$x = SendPOST ("http://10.10.10.1/userpost/xerox.set") ("_fun_function=HTTP_Machine_Reset_fn&NextPage=/status/rebooted.php");
############## script end ##############
or:
Corrected version posted below by klauskeys
#powershell script to remotely reboot networked HP and Xerox printers#ip values in plain text file printers.txt in the same directory as the script. ip's on separate lines.#philgman@gmail.com$SNMP = new-object -ComObject olePrn.OleSNMP$ErrorActionPreference = "Continue"<#Available choices for error action preference:•SilentlyContinue – error messages are suppressed and execution continues.•Stop – forces execution to stop, behaving like a terminating error.•Continue - the default option. Errors will display and execution will continue.•Inquire – prompt the user for input to see if we should proceed.•Ignore – (new in v3) – the error is ignored and not logged to the error stream. Has very restricted usage scenarios.#>#reset the $error[0].Exception value on start and repeat on each loop$error.clear()#read from list#return "Could not contact $_" if no response to ping#return "Failed $_" if it connects but can not set the valueGet-Content printers.txt | ForEach-Object { if (Test-Connection $_ -Count 1 -Quiet) #test connection to ip with single ping { setsnmp } else { Write-Output "Could not contact $_" } if ( $error[0].Exception -match "Exception calling") { Write-Output "Failed $_" } $error.clear() }#send snmp value# setting the integer vaue "4" to oid ".1.3.6.1.2.1.43.5.1.1.3.1" using the "private" community name forces the printer to rebootfunction setsnmp {$SNMP.open("$_","private",1,6000)$SNMP.Set(".1.3.6.1.2.1.43.5.1.1.3.1",4)
Neither of these 2 options are mine, so I can't help with the specifics.