11 December 2014

Uninstall All Printers

Posted By: Mick Pletcher - 4:50 PM

Share

& Comment






Recently, we upgraded our print servers and needed to reinstall all of the printers. This script will uninstall all printers. I deployed this script out and had it run as the user and a GPO reinstalled the printer with the new network location.

You can download the script from here: UninstallPrinters.ps1


 <#  
 .SYNOPSIS  
   Uninstall Printers  
 .DESCRIPTION  
   This script will uninstall all printers for a user  
 .PARAMETER <paramName>  
   <Description of script parameter>  
 .EXAMPLE  
   powershell.exe -executionpolicy bypass -file UninstallPrinters.ps1  
 #>  
   
 cls  
 $Printers = Get-WmiObject Win32_Printer  
 $EXE = $env:windir + "\system32\printui.exe"  
 $PrintUI = "/dn /n "  
 Foreach ($Printer in $Printers) {  
      If ($Printer.ShareName -ne $null) {  
           Write-Host "Uninstall"$Printer.ShareName"....." -NoNewline  
           $Parameters = $PrintUI + [char]34+ $Printer.Name + [char]34  
           $ErrCode = (Start-Process -FilePath $EXE -ArgumentList $Parameters -Wait -Passthru).ExitCode  
           If ($ErrCode -eq 0) {  
                Write-Host "Success" -ForegroundColor Yellow  
           } else {  
                Write-Host "Failed" -ForegroundColor Red  
           }  
      }  
 }  
   

About Mick Pletcher

My blog is here to help solve issues I have encountered and solved, publish scripts I have written, and educate others in understanding areas that are not well covered

0 comments:

Post a Comment

Copyright © 2013 Mick's IT Blogs™ is a registered trademark.