Powershell to remove a printer from a list of machines

TechInTheWoods
TechInTheWoods used Ask the Experts™
on
Hello,

I have a list of Windows 10 machines in a text file that I need to remove a printer named "Prt-lkm" from.

I need Powershell to loop through each machine in the list and remove that printer. I have tried a couple of iterations, but I'm missing something in each.

What is the best way to do this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Enterprise Business Process Architect
Commented:
$computers = Import-CSV "C:\SomeFolder\Computers.txt"
ForEach ($computer in $computers) {
  $computername = $computer.name
  Try {
    Remove-Printer -Name "Prt-lkm" -Computername $computername -erroraction stop
  }
  Catch {
    Write-Output "Unable to remove printer from computer $computername."
  }
}

Open in new window

or something along these lines.

Computers.txt would have the format of
Name
Computer1
Computer2
Computer3
Computer4
...

Open in new window

The first line of the file should be Name

Author

Commented:
Awesome, thanks! Worked great.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial