Printer Destroyer JSS Script

By | February 18, 2016

As part of a recent project, I have been tasked with removing old printers that were setup manually over a 5 year lease period by many different people. The only thing consistent with these installs were their inconsistency (and that they were configured via IP address using an HP Socket).

This project will be repeated at more-than 80 locations and I didn’t really want to add 100+ old printers to our JSS just to try to remove them. This led me down the path of trying to script it and use one of the script parameters in the JSS to customize each policy. This gives me a few benefits.

  1. I don’t have to add those 100+ removed printers to the JSS
  2. It could be added as a step to the new printer install policy saving the end user a step.
  3. It is reliable and repeatable for each location with minimal effort.

I’ve posted the script I devised on my GitHub page here:

We’ll talk about a few portions of the script and setup.

JSS Settings

Create a new script int the JSS by  going to https://your.jss.url:8443/scripts.html and clicking on the + (plus) icon next to new.

On the General tab, fill in the Display name, Category, Information and Notes fields similar to the image below.

Scripts General Tab

Then, click on the Script tab, and paste the script from GitHub into the Scripts Contents box.

Script Contents

Now, in the Options tab set your priority and add a parameter label:

Script Options Tab

When all looks correct, click Save.

You can now add this as a script in any policy (like your new printer setup policy!) and add in the IP address of any printer you want gone.

Script Added to Policy

Script Logic

We use a few commands in the script to delete the correct printer.

  • lpstat – This command shows printer status information. the -s flag shows us a summary of all installed printers.
  • lpadmin – This command adds/removes/configures printers.

To help with logging/troubleshooting in the JSS logs, the scripts print out the parameter value and present textual feedback along each step of the way.

One thing to note, this script doesn’t handle multiple printers with the same IP address Mac OS X warns you if you try to add multiple printers using the same IP/Hostname. Hopefully these will just be edge cases. If we experience issues, I may look at a more elegant way to handle this in the future.

Happy Printing!

Leave a Reply

Your email address will not be published. Required fields are marked *