{"id":3084,"date":"2013-08-08T00:01:00","date_gmt":"2013-08-08T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/08\/08\/use-powershell-in-windows-8-to-remove-printers\/"},"modified":"2013-08-08T00:01:00","modified_gmt":"2013-08-08T00:01:00","slug":"use-powershell-in-windows-8-to-remove-printers","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-in-windows-8-to-remove-printers\/","title":{"rendered":"Use PowerShell in Windows 8 to Remove Printers"},"content":{"rendered":"<p><strong style=\"font-size: 12px\">Summary<\/strong><span style=\"font-size: 12px\">: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell&nbsp;3.0 in Windows 8 to remove printers.<\/span><\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. The Scripting Wife and I have been talking to various people from the Charlotte Windows PowerShell User Group all week about doing another Windows PowerShell Saturday. It is an awful lot of work, but I think we are going to do this again. The Windows PowerShell Saturday in Charlotte sold out within a few days, and there have been many positive comments about the event. That means that people found it to be a valuable experience. So we will have another Windows PowerShell Saturday. (By the way, if you want to have one where you live, let us know via <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>.)<\/p>\n<p>To remove a printer with Windows PowerShell, I use the <strong>Remove-Printer<\/strong> function from the <strong>PrinterManagement<\/strong> module. There are two ways to use the <strong>Remove-Printer<\/strong> function:<\/p>\n<p style=\"padding-left: 30px\">Remove-Printer [-Name] &lt;String&gt; [-AsJob [&lt;SwitchParameter&gt;]] [-CimSession<\/p>\n<p style=\"padding-left: 30px\">&lt;CimSession&gt;] [-ComputerName &lt;String&gt;] [-PassThru [&lt;SwitchParameter&gt;]]<\/p>\n<p style=\"padding-left: 30px\">[-ThrottleLimit &lt;Int32&gt;] [-Confirm [&lt;SwitchParameter&gt;]] [-WhatIf<\/p>\n<p style=\"padding-left: 30px\">[&lt;SwitchParameter&gt;]] [&lt;CommonParameters&gt;]<\/p>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Remove-Printer [-AsJob [&lt;SwitchParameter&gt;]] [-CimSession &lt;CimSession&gt;]<\/p>\n<p style=\"padding-left: 30px\">[-PassThru [&lt;SwitchParameter&gt;]] [-ThrottleLimit &lt;Int32&gt;] -InputObject<\/p>\n<p style=\"padding-left: 30px\">&lt;CimInstance&gt; [-Confirm [&lt;SwitchParameter&gt;]] [-WhatIf [&lt;SwitchParameter&gt;]]<\/p>\n<p style=\"padding-left: 30px\">[&lt;CommonParameters&gt;]<\/p>\n<p>What this means is that if I type the exact printer name, I can use the <strong>Remove-Printer<\/strong> function directly. It also tells me that I can pipe a printer object to the function. By pipelining a printer object, I can use wildcard characters.<\/p>\n<h2>Begin with Get-Printer<\/h2>\n<p>I usually begin things by using a <strong>Get<\/strong> type of command. So the first thing I do is use the <strong>Get-Printer<\/strong> function to see what printers are defined. The command is shown here:<\/p>\n<p style=\"padding-left: 30px\">Get-Printer<\/p>\n<p>The command and its associated output are shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6237.hsg-8-8-13-01.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6237.hsg-8-8-13-01.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p><span style=\"font-size: 12px\">I can use a wildcard character to avoid typing a complete printer name as shown here:<\/span><\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-Printer | where name -Like &#8220;my*&#8221;<\/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\">myotherlaser&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Local&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Brother Laser Leg Typ&#8230;<\/p>\n<p>Or, I can type the exact printer name and supply it directly to the <strong>&ndash;Name<\/strong> parameter as shown here:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-Printer -Name myotherlaser<\/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\">myotherlaser&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Local&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Brother Laser Leg Typ&#8230;<\/p>\n<p>Both of these commands return printer objects, and therefore, they can be piped to the <strong>Remove-Printer<\/strong> function. This is shown here:<\/p>\n<p style=\"padding-left: 30px\">Get-Printer -Name myotherlaser | Remove-Printer<\/p>\n<p style=\"padding-left: 30px\">Get-Printer | where name -like &#8220;my*&#8221; | Remove-Printer<\/p>\n<h2>Remember Whatif<\/h2>\n<p>Of course, before I add a <strong>Remove-Printer<\/strong> object, I want to use the <strong>&ndash;Whatif<\/strong> switch to ensure that I am doing exactly what I want to do. Here is an example of a near disaster:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-Printer | where name -match &#8220;my*&#8221; | Remove-Printer -WhatIf<\/p>\n<p style=\"padding-left: 30px\">What if: Deleting printer Microsoft XPS Document Writer<\/p>\n<p style=\"padding-left: 30px\">What if: Deleting printer \\\\dc1.iammred.net\\HP LaserJet 2100 PCL6<\/p>\n<p style=\"padding-left: 30px\">What if: Deleting printer myotherlaser<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt;<\/p>\n<p>Luckily, I used <strong>&ndash;Whatif<\/strong>, so I did not delete a bunch of my printers.<\/p>\n<h2>Directly remove a printer<\/h2>\n<p>I can use the <strong>Remove-Printer<\/strong> function directly to remove a printer if I know the exact name. If I am unsure of the printer name, I use the <strong>Get-Printer<\/strong> function to list my printers, and I copy and paste the name. With quick edit mode turned on, I can highlight the printer name with my mouse, press ENTER to copy it to the clipboard, and then right-click to paste it. This is shown in the image that follows.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2766.hsg-8-8-13-02.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2766.hsg-8-8-13-02.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>Here is the command:<\/p>\n<p style=\"padding-left: 30px\">Remove-Printer -Name myotherlaser<\/p>\n<p>After I have deleted the printer, I may decide to delete the printer driver and the printer port (if necessary). To do that, I use the following functions:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-PrinterDriver -Name &#8220;Brother*&#8221;<\/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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PrinterEnvironment MajorVersion&nbsp;&nbsp;&nbsp; Manufacturer<\/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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&#8212;<\/p>\n<p style=\"padding-left: 30px\">Brother Laser Leg Type1 Class Dr&#8230; Windows x64&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Brother<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-PrinterDriver -Name &#8220;Brother*&#8221; | Remove-PrinterDriver<\/p>\n<p>I use the <strong>Get-PrinterPort<\/strong> function, and I decide that I do not need to remove any printer ports.<\/p>\n<p>That is all there is to using Windows PowerShell to remove printers. This also concludes Printer Week. Join me tomorrow when I will talk about running scripts on remote file shares.<\/p>\n<p><span style=\"font-size: 12px\">I invite you to follow me on <\/span><a style=\"font-size: 12px\" href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a><span style=\"font-size: 12px\"> and <\/span><a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a><span style=\"font-size: 12px\">. If you have any questions, send email to me at <\/span><a style=\"font-size: 12px\" href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a><span style=\"font-size: 12px\">, or post your questions on the <\/span><a style=\"font-size: 12px\" href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a><span style=\"font-size: 12px\">. See you tomorrow. Until then, peace.<\/span><\/p>\n<p><strong>Ed Wilson, Microsoft Scripting Guy<\/strong><span style=\"font-size: 12px\">&nbsp;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell&nbsp;3.0 in Windows 8 to remove printers. Microsoft Scripting Guy, Ed Wilson, is here. The Scripting Wife and I have been talking to various people from the Charlotte Windows PowerShell User Group all week about doing another Windows PowerShell Saturday. It is an awful lot [&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":[445,404,3,45],"class_list":["post-3084","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-client-side-printing","tag-printing","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell&nbsp;3.0 in Windows 8 to remove printers. Microsoft Scripting Guy, Ed Wilson, is here. The Scripting Wife and I have been talking to various people from the Charlotte Windows PowerShell User Group all week about doing another Windows PowerShell Saturday. It is an awful lot [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3084","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=3084"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3084\/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=3084"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=3084"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=3084"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}