Skip to main content

Adding A Printer for All Users (Windows)

The task at hand seems simple enough...install a printer for a Windows user for a printer on a Print Server. In our example, I'll use a print share called BigDill on a print server named Arkone.

Easy, right?  A quick web search for "powershell add printer" takes me to the add-printer cmdlet, and it is pretty easy to use for a print server.  The command looks like this (don't use this example!):

import-module printmanagement
add-printer -ConnectionName \\arkone\BigDill

I tested it locally outside of FileWave in the PowerShell ISE and it worked fine.  I ran the command, and it added the printer for me.  So, I created a fileset for the exact same thing and tried it out.  The result: nothing whatsoever.  The script seemed to run fine, but the user logged in didn't see a new printer!

So, why did this happen?  For two important reasons:

  1. The Add-Printer cmdlet is great, but it ONLY adds a printer for the current user
  2. When FileWave runs a script, it is always run under the context of the System account

When I investigated further by opening a command prompt as system, I found that in fact my fileset had run fine, and added the printer, but only for the system account.  

Testing Scripts for Use in FileWave
Review our KB Script Best Practices which demonstrates the use of psexec to run scripts on Windows as if they were run through FileWave (as System User and 32bit).

So, a little more research was required, and PowerShell in this instance is not the answer.  Instead, we are going to use a command-line utility in a batch file called printui.exe.  PrintUI can be used in many ways: Microsoft PrintUI Documentation

We won't get into all of the options of this command here, but printui can add a printer globally for all users using the /ga command line option (/gd is a global delete if you happen to want to add a removal script as well).  So our new batch file (Activation Script) code looks like this:

@echo off
printui /ga /n\\arkone\BigDill
exit 0

And our results, in this case, were excellent...the printer is added for every user at their next login.  (Given this, you may want to make this a reboot fileset)

And, for completeness' sake, if we wanted to add a post-uninstallation script to "clean-up" if this fileset were removed, we could do:

@echo off
printui /gd /n\\arkone\BigDill
exit 0