Printer scripts

From Piszczynski
Revision as of 15:33, 9 April 2019 by 31.3.228.2 (talk) (Created page with " == Powershell script to uninstall printer drivers and associated printer == { --------------------------------- write-host "Powershell version pre-5.1, running legacy scrip...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Powershell script to uninstall printer drivers and associated printer

{


write-host "Powershell version pre-5.1, running legacy script." $targetpc = read-host "Enter target PC name" $printernames = (Get-WmiObject Win32_PrinterDriver -ComputerName $targetpc).Name $count = 0 Foreach ($printername in $printernames)

   {
   if (!($printername.Contains('Microsoft')))
       {
       Write-Host "[$count] - $printername"
       }
   $count++
   }

$input = read-host "Select number printer to remove" $printer = (($printernames[$input]).Split(","))[0] $version = (($printernames[$input]).Split(","))[1] $os = ((($printernames[$input]).Split(","))[2]).Split(" ")[1]

$printerdrivers = (Get-WmiObject Win32_PrinterDriver -ComputerName $targetpc).Name foreach ($printername in $printernames)

   {
   if($printer -eq $printername)
       {
       get-service -name spooler -ComputerName $targetpc
       rename-item -path "hklm:\system\currentcontrolset\control\print\environments\windows x64\print processors\winprint" -newname winprint.old 
       Get-Service -Name "spooler" | Set-Service -Status Running
       get-service -name spooler
       rundll32 printui.dll,PrintUIEntry /dd /m "$printer" /h "$os" /v $version
       get-service -name spooler | stop-service -force
       rename-item -path "hklm:\system\currentcontrolset\control\print\environments\windows x64\print processors\winprint.old" -newname winprint
       Get-Service -Name "spooler" | Set-Service -Status Running
       }
   }

$printernames = (Get-WmiObject -class win32_printer -ComputerName $targetpc -Recurse) $printernames

  1. clear variables

$count = $null $printernames = $null



}