How to Automate Google Cloud Print Printer Sharing
KB Home | How to Automate Google Cloud Print Printer Sharing
Up until recently the only automated task in our Google Cloud Print integration was PaperCut’s publishing of the printers to GCP. Admins would then have to manually share many tens or hundreds of GCP printers to many hundreds or thousands of users. Even if an admin distills the cohorts of students, faculty, and staff to a relative few groups within one’s G Suite domain group list, this is still a huge drag. However, we have invested some effort in working out the steps to automate the sharing of GCP printers, and I will describe that here:
Automating the sharing and management of Google Cloud Print printers requires setting yourself up with the open source command line tool, Google Apps Manager. GAM requires that you authenticate it with one of your domain’s Super Admin accounts. The setup process will also initialize a personalized instance of GAM on Google Cloud Platform. The free license of Google Cloud Platform should support the GAM needs of most organizations. A subscription to Google Cloud Platform is not required. GAM’s Git Hub wiki has simple instructions for downloading, installing and starting to use it here: https://github.com/jay0lee/GAM/wiki.
Collect your domain’s groups and printers
Once your GAM project is up and running, the next step in the printer sharing automation process is to collect your organization’s list of groups and printer IDs since those are the attributes the command to share a printer requires.
This command writes to a CSV file the list of printers owned or accessible by the user GAM is running as:
gam print printers > printer_properties.csv
This command writes to a CSV file all the groups in the domain:
gam print groups > groups.csv
Creating the commands that will automate sharing
Next, open a new spreadsheet document in either Excel or Google Sheets and call it “Commands.” Open groups.csv and copy the emails column to Commands sheet’s column B. Then, open printer_properties.csv and copy the ID column to Commands sheet’s column C.
This should be close to what you have now:
The Commands sheet’s column A should still be blank because this is the column our formula will populate with all of the commands required to share every printer with every group.
Below is the formula that will list all possible command combinations of each printer ID and user group. Copy and paste it into cell A2.
=IF(ROW()-ROW($A$2)+1>COUNTA($C$2:$C$9)*COUNTA($B$2:$B$8),″,INDEX(“ ./gam printer “&$C$2:$C$9,INT((ROW()-ROW($A$2))/COUNTA($B$2:$B$8)+1))&INDEX(“ add user “&$B$2:$B$8,MOD(ROW()-ROW($A$2),COUNTA($B$2:$B$8))+1))
$B$2:$B$8 are the email column values, and $C$2:$C$9 are the printer ID list values. $A$2 references the cell the formula went into. These cell references can be customized based on your need. The text string element “ ./gam printer “ assumes you will be running the script from macOS (like me) or Linux but in all likelihood, you will execute from Windows, so remove the leading dot and slash as necessary.
Next, select and copy cell A2 and paste the formula into the rows below. All possible printer and email command combinations will be listed based on the two list values, like so:
Creating and executing your script
Then, copy and paste cells A2 through the end of the column into a new text file.
Save it as printers.cmd, and save it into your GAM directory.
Next, run the CMD file as a local administrator by right clicking and hitting “Run as administrator.”
In macOS and Linux:
Save it as printers, and save it into your GAM directory.
Next, launch terminal and CD to your GAM directory. Use chmod to make printers executable by you then run it as ./printers.
Depending on the number of printers and groups, this may take a while. Sharing this way will not send users a printer sharing notification, they will just appear on their list of available printers.