Here's my script to remove all printers
#!/bin/sh
launchctl stop org.cups.cupsd
#Then rename the the cupsd.conf file:
sudo mv /etc/cups/cupsd.conf /etc/cups/cupsd.conf.backup
#Restore the default cupsd.conf file:
sudo cp /etc/cups/cupsd.conf.default /etc/cups/cupsd.conf
#Then rename the printers.conf file:
sudo mv /etc/cups/printers.conf /etc/cups/printers.conf.backup
#Next, restart cups with:
sudo launchctl start org.cups.cupsd
I use a script very similar to @CasperSally. It looks like the problem you are having delivering it from the JSS is that the machine cannot mount your Casper Share. Can you deploy any other software or scripts to that machine?
As far as running from the terminal and not having it delete, try the script that Casper Sally listed above.
I was wanting to remove printers with UNIFLOW in the name used this. Pretty sure you could pull something useful out of it. Seemed to work without any issues.
echo "--Current printers"
lpstat -a | cut -d" " -f1 | while read PRTA
do
echo "-"$PRTA
done
lpstat -a | lpstat -a | cut -d" " -f1 | grep "UNIFLOW" | while read PRTB
do
echo "-- UNIFLOW printer detected attempting to delete: "$PRTB
lpadmin -x $PRTB
sleep 1
done
echo "--Remaining printers"
lpstat -a | cut -d" " -f1 | while read PRTC
do
echo "-"$PRTC
done
I have a self service policy that runs this command:
lpstat -p | cut -d" " -f2 | xargs -I{} lpadmin -x {}
Removes all installed printers. Works quite well.
@stevevalle - I run the exact same command. Awesome.
Sorry for such a late reply, but I finally got time to sit down and work on this.
I started with the script CasperSally posted. When I run that in terminal with the sh command I get the following:
launchctl stop error: No such process
mv: /etc/cups/printers.conf: No such file or directory
I then used sudo launchctl unload -w /System/Library/LaunchDaemons/org.cups.cupsd.plist and sudo launchctl load -w /System/Library/LaunchDaemons/org.cups.cupsd.plist. After that I tried the script with the sh command again and get:
mv: /etc/cups/printers.conf: No such file or directory
@stevewood][/url I am able to push things out otherwise, I wasn't sure if it was an issue with the script or how I uploaded in Casper Admin or how I tried to run it through a policy. I did use connect to server on one of the macs I'm working on to make sure I could reach both of my distribution points.
After all that, I tried the command lpstat -p | cut -d" " -f2 | xargs -I{} lpadmin -x {} that @stevevalle][/url posted. It gave me the following:
lpadmin: Undefined error: 0
That kept occurring until I stopped the command. It did seem to remove 1 printer though, but left 3. I'll keep my search up, but I appreciate your replies so far.
I tried the commands posted by @jacob_salmela in this thread: https://jamfnation.jamfsoftware.com/discussion.html?id=8695
When I run them individually they seem to work; The printers were cleared off of this system and the policies added back the appropriate printers. I tried running the script through terminal but it doesn't appear to do anything, would that behavior be the same if I upload the script to Casper Admin and deploy it with a policy? The other problem I'm running into is print jobs requiring a username and password. After printing the icon in the dock will bounce and say "Hold for authentication" even though there shouldn't be any security like that on the printer. Is that an option in the OS I can disable somewhere?
Hello all,
Great stuff in this thread. I wanted to pass along my solution to only remove mcx managed printers from the user's printer list. There are instances where we allow users to add unmanaged printers to their printer list and we don't want to remove those when we modify our own mcx printer configurations.
I modified @stevevalle's command above to only remove MCX printers:
lpstat -p | cut -d' ' -f2 | grep mcx | xargs -I{} lpadmin -x {}
Simple and effective.
I have a self service policy that runs this command:
lpstat -p | cut -d" " -f2 | xargs -I{} lpadmin -x {}
Removes all installed printers. Works quite well.
I know this post is from several years ago - but wondering if there is a way to change this script to name the printer I was removed? I don't want to remove all printers just one named HS Aux Workroom