I use JAMF to manage our lab computers, which should always have 2 printers set up (B&W and Color). I noticed recently that some of the computers have duplicate printers (some with as many as 2 B&W and 3 Color) and I want to clean that up.
My thinking was to:
1. Create Extension Attribute that tells me the number or printers installed on a computer
2. Create Smart Group that has as Criteria computers where the created EA is not 2 (there are other Criteria, but this is the relevant one)
3. Create policy scoped to that Smart Group that deletes all printers and pushes the PKG I have to reinstall the 2 printers.
After some troubleshooting I came up with the following for the EA:
#!/bin/sh
#Get list of printers installed on computer
printers="$(lpstat -a |awk '{print $1}')"
#Get number of printers
numberPrinters=$(echo "$printers" | wc -l)
#Write to Extension attribute
echo "<result> $numberPrinters </result>"
It seemed to work if I ran the first 2 individual commands in Terminal on a test computer (gave me the result of 3 for a computer that had 3 printers installed). I created the EA (named Printers Installed) in JSS, setting the Data Type to Integer and Input Type to macOS Script. Then I created a Smart Group with the Criteria "Printers Installed - IS NOT - 2" (figuring this would find computers with both too many and too few printers). When I saved everything and clicked to View the Smart Group, it did pull up some computers that had too many, but it didn't pull up all of them and it also pulled up one computer that had 2 printers.
This is the first EA I've tried to create, so I was wondering if anyone could tell if I was missing something obvious?
Thanks!