Printing a testpage from PowerShell

Todays challenge comes from trying to troubleshoot printers om AX 2012.

Some of the printing flows are not that straight forward and might require printing from a service account. If you do not want to log in as that user to the UI or mabee you are not able to you can use PowerShell to do a test print from the account. This functionality is not available directly in Windows but I found a PS function that does this which I modified a bit (original links below).

This function uses WMIC to list all printers and then send a test print to the printer. You can also use it without modifying the $printername by adding the parameter -printername.

Function out-TestPage
{
Param(
  [string]$printername = “\\printserver\printername”)

  $Printers = Get-CimInstance -ClassName Win32_Printer
  $Printer = $Printers | Where-Object Name -eq "$printername"
 Invoke-CimMethod -MethodName printtestpage -InputObject ($printer)
 Write-Host "Printing to $($printer).Name"
}

To run this as the service account, simply launch PowerShell och Powershell ISE as the account and run the Function Block. Then call the function using out-TestPage -printername “[the name of your printer]”

Links
Use PowerShell to Send Test Page to a Printer – Scripting Blog (microsoft.com)
[SOLVED] Print Test Page from PS – Printers & Scanners – Spiceworks

Print Spooler crashar…

Idag befinner vi oss i printerträsket…

På en maskin jag felsökte idag crashade printspoolern så for jag försökte göra något. Jag har varit inne och rensat upp på följande ställen:

c:\windows\system32\spool\printers
c:\windows\system32\spool\drivers
HKEY_LOCAL_MACHINE\SYSTEM\CURRENTCONTROLSET\CONTROL\PRINT\

Trots detta vägrade spoolen starta och förbli så. Efter lite letande hittade jag följande lilla guldklimp. När spoolens crashar i Windows hamnar det en log fil i C:\ProgramData\Microsoft\Windows\WER\ReportQueue

Här kan man se exakt vad som strular. I mitt fall var det hptcpmon.dll så jag gick helt enkelt till C:\Windows\system32 och döpte om den till hptcpmon.dll.old och sen startar spoolern igen…

/JP