Remove a printer installed by Profile Manager or MCX from the command line (or remote ARD command)

When Profile Manager installs a printer, the CUPS queue name doesn’t match what the user sees. You can get a list of those queues by typing lpstat -s. To remove the printer by the name you define in Profile Manager with a script, you’ll need to find out the CUPS name.

Here’s a one-liner to remove a printer that was automatically installed with Profile Manager:


export ptr="PRINTERNAME";lpstat -s | awk "\$4 ~ /$ptr/ {print \$3}" | tr -d : | xargs lpadmin -x

Just replace PRINTERNAME with the correct queue name.

Remove a printer or update a printer in Mac OS X Server Profile Manager

If you modify a printer in Mac OS X Server’s Profile Manager, the changes don’t always get updated in my experience. To get the updates, you need to remove the row in the database that references the old printer.

In Terminal, load psql and select the correct database:

sudo psql -U _devicemgr -d devicemgr_v2m0 -h /Library/Server/ProfileManager/Config/var/PostgreSQL

Find printers with the ‘select’ SQL command:

SELECT * FROM printers;

This will select all printers. You can also use SQL’s ‘WHERE’ clause to filter the results down even more.

To remove the offending entry, use the DELETE command:

DELETE FROM printers where id=[the 'id' column obtained from the previous list]

As soon as I did this, the new printer populated in Profile Manager.

Filtering drivers by computer model in MDT or SCCM

If you want to filter by computer model, first you’ll need to get the computer model name by running the ‘wmic‘ command in a DOS prompt, and then typing: ‘CSProduct Get Name‘. That should return something similar to this:


C:\Users\seppler>wmic
wmic:root\cli>CSProduct Get Name
Name
HP EliteDesk 800 G1 USDT

Then, you’ll want to add a conditional Inject Drivers command, with the condition being a WMI query for:

SELECT * FROM Win32_ComputerSystem WHERE Model LIKE "%EliteDesk 800 G1%"

Replace the “EliteDesk 800 G1″ string with whatever model you want to match. The percents on each side are a typical SQL wildcard, which is why I don’t have to include ‘HP’ or ‘USDT’.

Windows Deployment Failure

When deploying a Windows 7 64-bit image from our deployment server (using Microsoft Deployment Toolkit, or MDT), we would run into an error message after the image had been applied to a workstation:

Windows could not parse or process the unattend answer file [C:\windows\Panther\unattend.xml] for pass [specialize]. A component or setting specified in the answer file does not exist

It turned out that Internet Explorer 10 had been installed. To fix the issue, you need to remove the IEWelcomeMsg entry from the answer file (either by editing unattend.xml manually on the server for the task sequence, or using Windows System Image Manager (WSIM).

This post clued me into the issue.

Signing iOS mobileconfig files with your certificate

If you’ve ever used Apple’s iPhone Configuration Utility, you’ve probably noticed that it says ‘Unsigned’ when you send the .mobileconfig file to your device. To sign the profile, export or email the config file to yourself, have your certificate files handy, and type the following:

openssl smime \
-sign \
-signer your-cert.pem \
-inkey your-priv-key.pem \
-certfile TheCertChain.pem \
-nodetach \
-outform der \
-in ConfigProfile.mobileconfig \
-out ConfigProfile_signed.mobileconfig

The files you’ll need are:

your-cert.pem – this is the certificate you’ve been issued
your-priv-key.pem – this is your private key
TheCertChain.pem – this is the certificate chain (optional, in some cases)
ConfigProfile.mobileconfig – This is the unsigned copy of your configuration profile

The original instructions are located here.

Discovering all Bonjour services

To discover all Bonjour services, do the following:

NSNetServiceBrowser
searchForServicesOfType: @"_services._dns-sd._udp."
inDomain: @""

It will return data in the following form:

NSNetService
name = "_workstation"
type = "_tcp.local."
domain = "."

All this documentation taken from here.

Fixing Mac OS X 10.6’s ping command (aka, removing Request timeout for icmp_seq #)

If you are like me, and annoyed that OS X 10.6’s ping command displays the following text when it cannot reach a host:

Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2

Then you’ll be happy for the fix. You can either download the source code to the ping command from Apple and edit it yourself, or you can download my pre-compiled copy.

If you choose to edit it yourself, you’ll want to comment out lines 977 and 978 so they look like this:

// if (!(options & F_QUIET))
// printf("Request timeout for icmp_seq %ld\n", ntransmitted - 2);

Then just type ‘gcc ping.c’ and you’ll end up with a file called a.out, which you can use to replace /sbin/ping, or put in your local ~/bin directory if you’ve got one.

HP Print Driver Crash when printing to networked printers

I ran into an issue recently where any application would crash when printing to a network printer. Our environment is unique in that we are printing to a Windows print server (using Guest privileges), but users on the network are logging in using the Novell client.

The crash would not happen with generic Microsoft drivers that came with Windows XP, but it would happen with any HP-branded drivers. Our first workaround was just to use PCL or PostScript drivers that closely matched the printer, and hope for the best.

In the end, we found out that when printing with the HP drivers, it would write to a file in the Windows directory called hpmnwun.ini. The contents it would write were:


[NWUSERNAME]
NOVELL=1
NWUSERNAME=testuser

Fixing the issue was a two step process:

1: Erase the contents of the file
2: Change the NTFS Permissions of the file to make it read-only by all users (even Administrators)

I think this forces the HP drivers to print to the printer in the standard Windows printer sharing way. When the HP drivers detect the Novell client installed, it writes the NWUSERNAME info to the file and must try to print in an ‘NDPS friendly’ way, which causes the application to crash when printing to a standard Windows shared printer and not a NDPS printer.

Adding Printers to OS X from the Command Line

After a little searching, I found out you can add printers to OS X from the command line using this syntax:

lpadmin -p Printer_Name -L "Printer Location" -E -v lpd://x.x.x.x -P /Library/Printers/PPDs/Contents/Resources/en.lproj/Printer_Driver.gz

If you don’t specify the -P option, it will not show up in your Print or Printer Setup dialogs. If you want to include the generic PPD, it is located here:

/System/Library/Frameworks/ApplicationServices.framework/Versions \ /A/Frameworks/PrintCore.framework/Versions/A/Resources/Generic.ppd

That path is all one line, with no spaces.