Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

Help w/ Object Looping & Removing Specific Printers

$
0
0

Hello there! I’m fairly new to PowerShell scripting and I’m trying to figure out something I think should be pretty simple to anyone relatively familiar with PS.

I want to remove specific printers from my computer based on a list.

$printers = Get-WmiObject Win32_Printer $printerNames = $printers | Select-Object -Property "Name" | Where-Object {$_.Name -Like 'xxxxx'} 

The part I’m having trouble with is to solve this issue I’ve decided to use a nested foreach loop. So I’ve done something like:

foreach ($printer in $printers) { foreach ($printerName in $printerNames) { if ($printer.Name -eq $printerName { # remove printer code here } } } 

The problem is the output for $printer or $printerName in the loops is not what I want… it dumps long instances w/ DeviceID’s – and the Name output looks like a SQL variable starting with @{Name= blah blah..

What do I need to do to properly utilize that WmiObject in these foreach loops? THANK YOU IMMENSELY for any help!

submitted by /u/Myollinir
[link] [comments]

The post Help w/ Object Looping & Removing Specific Printers appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793

Latest Images

Trending Articles



Latest Images