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.

$host.Runspace.ThreadOptions = "ReuseThread"
Add-Type -AssemblyName System.Printing
$permissions = [System.Printing.PrintSystemDesiredAccess]::AdministrateServer
$queueperms = [System.Printing.PrintSystemDesiredAccess]::AdministratePrinter
$server = new-object System.Printing.PrintServer -argumentList $permissions
$queues = $server.GetPrintQueues(@([System.Printing.EnumeratedPrintQueueTypes]::Shared))

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.

foreach ($q in $queues) { 
#Get edit Permissions on the Queue
$q2 = new-object System.Printing.PrintQueue -argumentList $server,$q.Name,1,$queueperms

From here it is just a matter of finding devices that support the desired PrintCapability and then setting it to the desired value. We'll be using the DuplexingCapability object in this example.

	$duplexCaps = $q2.GetPrintCapabilities().DuplexingCapability
if ($duplexCaps.Contains([System.Printing.Duplexing]::TwoSidedLongEdge)) {
$q2.DefaultPrintTicket.Duplexing = [System.Printing.Duplexing]::TwoSidedLongEdge

Putting it all together:

$host.Runspace.ThreadOptions = "ReuseThread"
Add-Type -AssemblyName System.Printing
$permissions = [System.Printing.PrintSystemDesiredAccess]::AdministrateServer
$queueperms = [System.Printing.PrintSystemDesiredAccess]::AdministratePrinter
$server = new-object System.Printing.PrintServer -argumentList $permissions
$queues = $server.GetPrintQueues(@([System.Printing.EnumeratedPrintQueueTypes]::Shared))

foreach ($q in $queues) {
#Get edit Permissions on the Queue
$q2 = new-object System.Printing.PrintQueue -argumentList $server,$q.Name,1,$queueperms

#Set DefaultPrintTicket
$duplexCaps = $q2.GetPrintCapabilities().DuplexingCapability
if ($duplexCaps.Contains([System.Printing.Duplexing]::TwoSidedLongEdge)) {
$q2.DefaultPrintTicket.Duplexing = [System.Printing.Duplexing]::TwoSidedLongEdge

This is of course, just one example of what you could do now that you've got the System.Printing namespace mapped into PowerShell.


Justin Hutchings & Alan Morris


Comments (19)
  1. Nice post, I tweaked the code a bit so I could pull queues from my print server ps but am getting an error.

    $host.Runspace.ThreadOptions = "ReuseThread"

    Add-Type -AssemblyName System.Printing

    $server = new-object System.Printing.PrintServer("\ps")

    $queues = $server.GetPrintQueues(@([System.Printing.EnumeratedPrintQueueTypes]::Shared))


    Add-Type : Length cannot be less than zero.

    Parameter name: length

    At line:1 char:9

    + Add-Type <<<<  -AssemblyName System.Printing

       + CategoryInfo          : NotSpecified: (:) [Add-Type], ArgumentOutOfRangeException

       + FullyQualifiedErrorId : System.ArgumentOutOfRangeException,Microsoft.PowerShell.Commands.AddTypeCommand

    I'm running this on windows 7 x64 enterprise. I have all the rsat tools installed, but I figure I must be missing something.

  2. Anonymous says:


    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.


    Justin [MSFT]

  3. Anonymous says:

    Be sure to check out the new PowerShell scripts provided in Windows 8 Consumer preview for printer management.…/hh918357.aspx

  4. Print Blog says:

    Jeffrey, thanks a lot.  That is helpful content!

  5. n3tboss says:

    Dear Justin Hutchings & Alan Morris,

    I tried your Powershell source Code to change from Simplex to duplex.

    I do not get any errors, but the Driver is still simplex.

    I tried to change these settings with WMI (win32_printerconfiguration) but I was unsuccessfull.

    Please do not misunderstand, I will not have a script which works… 🙂

    I am just looking for a possibilitie to change from simplex to dupelx and from color to B/W.

    Do you think there is a possibilitie?

    All classes which I found are readOnly…

    I like this Blog so please update it.

    thanks and regards


  6. Anonymous says:

    Can someone please provide assistance in adapting this script to check the Printer Driver version?

  7. Anonymous says:


    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.

    Thanks in advance…


  8. Mathieu says:

    Justin ,

    Could you please post un exemple with a new schema. I have do modify the PagePerSheet property an it doesn't work.



  9. JoshGav says:

    The scripts in this post are a good start, but I couldn't actually make things work till I did the following:

    $host.Runspace.ThreadOptions = "ReuseThread"

    Add-Type -AssemblyName System.Printing

    $permAdminServer = ([System.Printing.PrintSystemDesiredAccess] "AdministrateServer")

    $permAdminPrinter = ([System.Printing.PrintSystemDesiredAccess] "AdministratePrinter")

    $ps = New-Object System.Printing.LocalPrintServer $permAdminServer

    $queue = $ps.GetPrintQueues() | Select-Object -Last 1

    $queue2 = New-Object System.Printing.PrintQueue $ps,$queue.Name,$permAdminPrinter

  10. lucylitho says:

    <p><a href="http://;  > flyer printers uk </a></p>is a business leader in handling  any type of print projects for marketing needs.  

    Our products are brochures, catalogs, postcards,

    Business cards, banners, plastic cards, leaflet , sticker etc.

    Affordability, high quality and fast turnarounds are our area of focus.

  11. bdailey says:

    Justin –

    I get an error at the following line of your script:

    $q2 = New-Object System.Printing.PrintQueue $server,$q.Name,$queuePerms

    The error reads something like this:

    "Attempt by security transparent method 'MS.Internal.PrintWin32Thunk.PrinterDefaults.Dispose(Boolean)' to access security critical method 'MS.Internal.PrintWin32Thunk.PrinterDefaults.InternalDispose(Boolean)' failed."

    I've googled this and found that it's a known bug in the .NET v4.0 assembly System.Printing, and the workarounds I've found do not work for me… Any pointers?



  12. Premiquickprints says:

    we offered cheap and best high quality printing services like business card, gifts, T-shirts, mugs , stationary products, corporate products, etc. only at

  13. Michal Olejniczak says:


    This scrip work only with local printers. How can I change network printer installes on my computer with PowerShell?

  14. Ninad.kapse says:

    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

    Any inputs are much appreciated

    Thanks and Regards,


  15. Fredrik Holm says:


    I know this is an old thread but I'll give it a try – I have the same question as Michal – how can I do this on network printers on my computer?

  16. IT Managed Services in gold coast says:

    The Samsung ML-2955DW mono laser printer is notable for its very low street price and its full network connectivity, namely USB, ether-net and Wi-Fi.
    Cloud computing in gold coast

  17. Sarath says:

    Hello Justin

    Can u tell us how enable the same duplexing in a remote computer through pssession in powershell.

  18. team sport banners says:

    This really answered my problem, thank you!

Comments are closed.

Skip to main content