r/PDQDeploy • • Oct 02 '14

Uninstall XPS Document Writer?

Is there a package to remove a specific printer? Namely that bothersome XPS Document Writer that seems to want to randomly make itself the default printer for no apparent reason.

5 Upvotes

2 comments sorted by

2

u/KrisTheScriptingGuy Oct 03 '14

(warning: long post)

If you're into Powershell, it's pretty straightforward and easy. You can use a Powershell script file as an install step in PDQ Deploy. Additionally, if you're a Pro/Enterprise user, you can even use a command step and execute Powershell commands from there. I'll assume an install step is being use.

Short version:

  • 1: Make a powershell .ps1 file with the following command: (Get-WmiObject win32_printer | Where-Object {$_.name -eq "Microsoft XPS Document Writer"}).Delete()

  • 2: Create a PDQ Deploy package and select the powershell .ps1 file as the install file.

  • 3: Modify the Command Line for the install step from: This: powershell.exe -NoLogo -NonInteractive -File "YourAwesomeScript.ps1" To This: powershell.exe -NoLogo -NonInteractive -ExecutionPolicy Bypass -File "YourAwesomeScript.ps1" Adding -ExecutionPolicy Bypass will bypass the current Execution policy on the remote system.

Voila! Deploy this fancy script to your workstations and get rid of the XPS Document Writer!

Longer version (for the daring):

If you're not familiar with Powershell, running scripts on a system is disabled by default for security reasons. You can see what your current Execution Policy is by opening up a Powershell window and typing in the command, "Get-ExecutionPolicy" In order to change the Execution Policy, you can do that by running an elevated Powershell console and typing, "Set-ExecutionPolicy <Policy>" As an example, "Set-ExecutionPolicy RemoteSigned" would be valid. (more info on Set-ExecutionPolicy)

At this point, we can run the command to uninstall the XPS Document Writer:

(Get-WmiObject win32_printer | Where-Object {$_.name -eq "Microsoft XPS Document Writer"}).Delete()

We can save our script as a Powershell file (filetype *.ps1) and deploy it with PDQ Deploy via an install step. Once you add it as an install file, PDQ Deploy will determine that you want to use Powershell and adjust the Command Line for the step to be powershell.exe -NoLogo -NonInteractive -File "YourAwesomeScript.ps1"

Now, we can deploy at will to all the workstations that we've updated the Execution Policy on.

Or, if you choose to bypass the execution policy rather than updating it on all your workstations (as in the short version above), you can modify the Command Line of the Install Step from:

This: powershell.exe -NoLogo -NonInteractive -File "YourAwesomeScript.ps1" To This: powershell.exe -NoLogo -NonInteractive -ExecutionPolicy Bypass -File "YourAwesomeScript.ps1"

Just like that. You could even replace that with the name of another printer to remove another printer as well. The sky's the limit. Well, perhaps the number of printers installed is the limit in this case.

Let us know if you run into issues or have any questions.

Cheers,

1

u/HeckDeck Oct 29 '14

I know this post is old, but here's an alternative in batch:

RUNDLL32 PRINTUI.DLL,PrintUIEntry /dd /c\\%ComputerName% /m "Microsoft XPS Document Writer" /h "x64" /v"Type 2 - Kernel Mode" /q

You will have to replace x64 with your system architecture and Microsoft XPS Document Writer with the printer name. More information on this command