Printer Management Using PowerShell

*******Disclaimer. This posting contains scripting samples. These are
provided as-is with no guaranties or warranties of any kind. They are
not thoroughly tested in all scenarios.

Over the years, the Printing team has released a number of management technologies designed to help print administrators get their jobs done. While the Print Management Console (PMC) is the tool of choice for many, sometimes you need a scripted solution. This is where PowerShell comes in.

One of the beautiful things about PowerShell is that it provides a single entry point to a wide array of scripting tools. For instance, you can manage WMI objects, .NET objects, call console apps like SetPrinter.exe and even (if you’re adventurous) marshal native API calls through .NET to PowerShell. For the purposes of this post, though, I’m going to keep things planted firmly in what you can do using the objects provided in .NET 3.0+.

One common administrative scenario would be setting all of the print queues on a print server to print double sided or duplexed. We could do this in the PMC, but we would need to edit each queue one-by-one: not fun. Fortunately, the Print Schema (introduced in Windows Vista) provides a common syntax that we can script against, and .NET provides a number of convenient objects to represent some of the common keywords.

Let’s go to the code. First, we need to change our threading model so that everything plays nice. Then we get into the real work of importing the correct namespace (System.Printing) and set up some objects we’ll be using. Note that we're filtering the queues we get back from the (local) server using a flag from System.Printing.EnumeratedPrintQueueTypes so that we only get shared queues. You could add more flags into the array we pass to GetPrintQueues() as well.

Now that we have a collection of PrintQueue objects in $queues, we can iterate over them in a foreach loop. The first challenge we’ll need to deal with is getting a PrintQueue object where we have administrative privileges. Note: You will most likely have to run PowerShell as an administrator in order to get permission to modify the PrintQueue object.

The driver you are working with may not support the Duplexing feature in the public namespace of the PrintSchema. You can confirm whether or not the feature is available on the PrintQueue by adding an else statement after the if statement. If that’s the case, you’ll have to alter the DefaultPrintTicket’s XML directly to manage it. The PrintSchema Specification has would be a good reference if you need to do that.

I need a script to change the printer settings mode to duplex or both sides. This will help me in saving paper, cause accidendly a couple of times I have sent the print job without changing the settings.

I want to get security permission Administrators group on printer object in windows 2003 using power shell. i am not able to do by power shell as get security Descriptor method is not present in windows 2003 can any one help me to get this done using power shell