Print test page on default printer

I thought this would be simple, but apparently not. I would like to send a test page to the default printer on the workstation I’m logged into. It should be the same test page I would get if I opened Printers and Scanners, opened the default printer, clicked “print test page”.

I’ve seen some examples where I can specify a printer name, but I would like the script to always go to what printer is configured as the workstation’s default, so that I can just run it to confirm where the print job shows up.

Suggestions?

—K

Give this a try:

(Get-CimInstance Win32_Printer -Filter "Default = TRUE").PrintTestPage()

Thanks, Rich! Tried the code, but got this

PS P:> (Get-CimInstance Win32_Printer -Filter “Default = TRUE”).PrintTestPage()
Method invocation failed because
[Microsoft.Management.Infrastructure.CimInstance] does not contain a
method named ‘PrintTestPage’.
At line:1 char:1

  • (Get-CimInstance Win32_Printer -Filter “Default = TRUE”).PrintTestPag

    • CategoryInfo : InvalidOperation: (PrintTestPage:String)
      , RuntimeException
    • FullyQualifiedErrorId : MethodNotFound

Did I miss something?

—K

Get-CimInstance Win32_Printer -Filter "Default = TRUE" | Invoke-CimMethod -MethodName PrintTestPage

At least for me this had to be run in an elevated PS session

Thank you, Darwin!! Worked perfectly for me, two workstations, two non-admin users.

It’s funny. in the interim I tapped AI to write something, and it returned 35 lines of code to do just this.

It seems we may not be in as much danger as the hype-crowd would like us to stress about.

Much appreciated!

—K

If the printer is installed for “all users” (i.e., it’s a “system level” device) it needs elevation. If the printer is installed for a specific user and that user runs the code, elevation isn’t needed.

That must be the reason. I run a short PS script install the printer and make it default.

It runs under the user’s profile, so that follows.

Thanks, again!

—K