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

Comments

Leave a Reply

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Find out more about Webmentions.)