Active Directory – Create Printer Queue with Powershell

Today I needed to create a lot of Print Queues in a Remote Domain, which I thought it should not be that hard with all the cmdlets given from Microsoft. But with my first shots with some cmdlets and also with the usage of my preferred Search engine, I could not find a working solution throughout PowerShell to create Printer Queues. I found other people with the same needs, but with no solution and I found a working VBScript, but I needed to put the Block into a PowerShell script, rather than executing a VBScript out of PowerShell.
After a lot of trying and understanding, I could get a Script working:
Active Directory create Print Queue Object with Powershell

And here you can copy my script if you like to:

$OUString = "LDAP://hosebeidc02.deheim.hosebei.ch/OU=PrinterQueues,DC=deheim,DC=hosebei,DC=ch"

$OUObject = New-Object directoryservices.directoryentry $OUString

$newprinter= $OUObject.get_Children().Add("cn=ExamplePrinter","printQueue")
$newprinter.get_Properties()["PrinterName"].Add("ExamplePrinter")
$newprinter.get_Properties()["uNCName"].Add("\\ExampleServer\ExamplePrinter")
$newprinter.get_Properties()["DisplayName"].Add("ExamplePrinter Description") #Optional
$newprinter.get_Properties()["ServerName"].Add("ExampleServer.deheim.hosebei.ch")
$newprinter.get_Properties()["Location"].Add("Example/Location") #Optional
$newprinter.get_Properties()["description"].Add("Example Description") #Optional
$newprinter.get_Properties()["drivername"].Add("Example Drivername") #Optional
$newprinter.get_Properties()["printcolor"].Add($true) #Can print colored, else $false
$newprinter.get_Properties()["printDuplexSupported"].Add($true) #Can print with Duplex Support
$newprinter.get_Properties()["printStaplingSupported"].Add($true) #Can staple
$newprinter.get_Properties()["versionnumber"].Add("1") #Version Number starts with 1
$newprinter.get_Properties()["shortservername"].Add("ExampleServer")
$newprinter.get_Properties()["printMaxResolutionSupported"].Add("300")

$newprinter.commitChanges()

There are more attributes that can be set, and even on my List are some Optional, I marked them with a comment at the end of the line.
If you know a better solution, please let me know.

Hope this helps someone

One thought on “Active Directory – Create Printer Queue with Powershell

  1. It certainly helped me with my use case! I needed to create AD objects for print queues that are sitting behind a load balancer. I’ve been trying to find a solution for days! Thank you!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.