Quantcast
Channel: TechNet Blogs
Viewing all articles
Browse latest Browse all 34890

Weekend Scripter: Easily Publish all Printers on a Print Server to Active Directory

$
0
0

Summary: Microsoft Scripting Guy, Ed Wilson, shows how to use Windows PowerShell 3.0 to publish printers in Active Directory Domain Services (AD DS).

Microsoft Scripting Guy, Ed Wilson, is here. While I was studying for one of the tests for the new MCSE for server infrastructure, Exam 70-410: Installing and Configuring Windows Server 2012, I ran across the Configure print and document services exam objective, and I began to think about publishing printers to Active Directory.

Note   Actually, the cool thing about Windows PowerShell on Windows Server 2012 is that nearly everything that needs to be accomplished is doable via Windows PowerShell. So, this actually becomes a bit of a problem for me, because I am not always familiar with the GUI utilities, or other command-line utilities. This is one of the real reasons that I like to take certification exams on our new products—it helps me to get to know the capabilities of the product, and it also gets me out of my shell (pun intended) when it comes to administration.

Well, anyway, because there was not much Windows PowerShell on the exam, as I would have liked, I thought it would be cool to do a little Windows PowerShell to solve some of the objectives.

First find printers on the server

To find all of the printers defined on the server, I use the Get-Printer function. The output, appearing here, provides the printer name, computer name, type, and the name of the printer driver.

PS C:\> Get-Printer

 

Name                           ComputerName    Type         DriverName

----                           ------------    ----         ----------

Microsoft XPS Document Writ...                 Local        Microsoft XPS Documen...

Fax (redirected 1)                              Local        Microsoft Shared Fax ...

MS Publisher Imagesetter                       Local        MS Publisher Imagesetter

MS Publisher Color Printer                     Local        MS Publisher Color Pr...

Generic IBM Graphics 9pin                      Local        Generic IBM Graphics ...

Microsoft XPS Document Writer                  Local        Microsoft XPS Documen...

 

Unfortunately, the Get-Printer function does not have a –published parameter nor does it have very much filtering capability. To obtain a better idea of the type of information returned by the Get-Printer function, I pipe the output to the Format-List cmdlet, and I choose all properties (fl * is the alias). The command is shown here.

Get-Printer | fl *

The command and its associated output is shown here.

Image of command output

Finding printers on the server that are not published to AD DS

To find printers that are not published to Active Directory Domain Services, I need to use the Where-Object cmdlet to filter out printers that have a value for the published property that is equal to $false. I use the command appearing here.

Get-Printer | ? published -eq $false

When I run the command, I see that there are numerous printers that are not published to AD DS. The command and its associated output is shown here.

Image of command output

Publish all non-published printers to AD DS

Now that I know I can find all non-published printers, I need to figure out a way to publish the printers in AD DS. Fortunately, this is pretty easy. I use the Set-Printer function. Luckily, the Set-Printer function has a –publishedparameter, and I can assign a value of $true to it. I arrive at the following command.

Get-Printer | ? published -eq $false | Set-Printer -Published:$true

When I run the command, a couple of errors arise. The command and its associated errors are shown here.

Image of command output

When I check to see if there are any AD DS published printers, I now see that there are three published printers.

PS C:\> Get-Printer | ? published -eq $true

 

Name                           ComputerName    Type         DriverName

----                           ------------    ----         ----------

MS Publisher Imagesetter                       Local        MS Publisher Imagesetter

MS Publisher Color Printer                     Local        MS Publisher Color Pr...

Generic IBM Graphics 9pin                      Local        Generic IBM Graphics ...

The printers that generated the errors are the printers (such as the XPS document writer) that don’t make sense to share out across the network.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy 


Viewing all articles
Browse latest Browse all 34890

Trending Articles