{"id":4257,"date":"2013-01-26T00:01:00","date_gmt":"2013-01-26T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/01\/26\/weekend-scripter-easily-publish-all-printers-on-a-print-server-to-active-directory\/"},"modified":"2013-01-26T00:01:00","modified_gmt":"2013-01-26T00:01:00","slug":"weekend-scripter-easily-publish-all-printers-on-a-print-server-to-active-directory","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/weekend-scripter-easily-publish-all-printers-on-a-print-server-to-active-directory\/","title":{"rendered":"Weekend Scripter: Easily Publish all Printers on a Print Server to Active Directory"},"content":{"rendered":"<p><strong style=\"font-size: 12px\">Summary:<\/strong><span style=\"font-size: 12px\"> Microsoft Scripting Guy, Ed Wilson, shows how to use Windows PowerShell&nbsp;3.0 to publish printers in Active Directory Domain Services (AD DS).<\/span><\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. While I was studying for one of the tests for the <a href=\"http:\/\/www.microsoft.com\/learning\/en\/us\/mcse-server-infrastructure-certification.aspx\" target=\"_blank\">new MCSE<\/a> for server infrastructure, <a href=\"http:\/\/www.microsoft.com\/learning\/en\/us\/exam.aspx?ID=70-410\" target=\"_blank\">Exam 70-410: Installing and Configuring Windows Server 2012<\/a>, I ran across the <em>Configure print and document services <\/em>exam objective, and I began to think about publishing printers to Active Directory.<\/p>\n<p style=\"padding-left: 30px\"><strong>Note<\/strong>&nbsp; &nbsp;Actually, the cool thing about Windows PowerShell on Windows Server&nbsp;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&mdash;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.<\/p>\n<p>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.<\/p>\n<h2>First find printers on the server<\/h2>\n<p>To find all of the printers defined on the server, I use the <strong>Get-Printer<\/strong> function. The output, appearing here, provides the printer name, computer name, type, and the name of the printer driver.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-Printer<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ComputerName&nbsp;&nbsp;&nbsp; Type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DriverName<\/p>\n<p style=\"padding-left: 30px\">&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&#8212;&nbsp;&nbsp;&nbsp; &#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;-<\/p>\n<p style=\"padding-left: 30px\">Microsoft XPS Document Writ&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Local&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft XPS Documen&#8230;<\/p>\n<p style=\"padding-left: 30px\">Fax (redirected 1) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Local&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft Shared Fax &#8230;<\/p>\n<p style=\"padding-left: 30px\">MS Publisher Imagesetter&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Local&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MS Publisher Imagesetter<\/p>\n<p style=\"padding-left: 30px\">MS Publisher Color Printer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Local&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MS Publisher Color Pr&#8230;<\/p>\n<p style=\"padding-left: 30px\">Generic IBM Graphics 9pin&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Local&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Generic IBM Graphics &#8230;<\/p>\n<p style=\"padding-left: 30px\">Microsoft XPS Document Writer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Local&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft XPS Documen&#8230;<\/p>\n<p>&nbsp;<\/p>\n<p>Unfortunately, the <strong>Get-Printer<\/strong> function does not have a <strong>&ndash;published<\/strong> parameter nor does it have very much filtering capability. To obtain a better idea of the type of information returned by the <strong>Get-Printer<\/strong> function, I pipe the output to the <strong>Format-List<\/strong> cmdlet, and I choose all properties (<strong>fl *<\/strong> is the alias). The command is shown here.<\/p>\n<p style=\"padding-left: 30px\">Get-Printer | fl *<\/p>\n<p>The command and its associated output is shown here.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1134.HSG-1-26-13-01.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1134.HSG-1-26-13-01.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<h2>Finding printers on the server that are not published to AD DS<\/h2>\n<p>To find printers that are not published to Active Directory Domain Services, I need to use the <strong>Where-Object<\/strong> cmdlet to filter out printers that have a value for the <strong>published<\/strong> property that is equal to <strong>$false<\/strong>. I use the command appearing here.<\/p>\n<p style=\"padding-left: 30px\">Get-Printer | ? published -eq $false<\/p>\n<p>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.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1452.HSG-1-26-13-02.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1452.HSG-1-26-13-02.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<h2>Publish all non-published printers to AD DS<\/h2>\n<p>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 <strong>Set-Printer<\/strong> function. Luckily, the <strong>Set-Printer<\/strong> function has a <strong>&ndash;published<\/strong><em> <\/em>parameter, and I can assign a value of <strong>$true<\/strong> to it. I arrive at the following command.<\/p>\n<p style=\"padding-left: 30px\">Get-Printer | ? published -eq $false | Set-Printer -Published:$true<\/p>\n<p>When I run the command, a couple of errors arise. The command and its associated errors are shown here.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2364.HSG-1-26-13-03.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2364.HSG-1-26-13-03.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>When I check to see if there are any AD DS published printers, I now see that there are three published printers.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-Printer | ? published -eq $true<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ComputerName&nbsp;&nbsp;&nbsp; Type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DriverName<\/p>\n<p style=\"padding-left: 30px\">&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&#8212;&nbsp;&nbsp;&nbsp; &#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;-<\/p>\n<p style=\"padding-left: 30px\">MS Publisher Imagesetter&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Local&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MS Publisher Imagesetter<\/p>\n<p style=\"padding-left: 30px\">MS Publisher Color Printer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Local&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MS Publisher Color Pr&#8230;<\/p>\n<p style=\"padding-left: 30px\">Generic IBM Graphics 9pin&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Local&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Generic IBM Graphics &#8230;<\/p>\n<p>The printers that generated the errors are the printers (such as the XPS document writer) that don&rsquo;t make sense to share out across the network.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><strong>Ed Wilson, Microsoft Scripting Guy<\/strong>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, shows how to use Windows PowerShell&nbsp;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 [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[402,403,404,3,61,45,368],"class_list":["post-4257","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-mcse","tag-print-servers-print-queues-and-print-jobs","tag-printing","tag-scripting-guy","tag-weekend-scripter","tag-windows-powershell","tag-windows-server-2012"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, shows how to use Windows PowerShell&nbsp;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 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/4257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=4257"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/4257\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=4257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=4257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=4257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}