Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filtering a Get-printer variable output

Tags:

powershell

I need to get all the printers named with a printer name starting with P0

I'm new to PowerShell and the command get-printer did not support my syntax for the filtering. My output variable is empty.

I have tried filtering the command results and tried filtering the content of the results variable with all printers without success.

$PrinterList = Get-Printer -ComputerName "PrintServer" -Filter {name -like 'P0'}

Or

$PrinterList = Get-Printer -ComputerName "PrintServer"

$PrinterSort = $PrinterList.Name | Where-Object {$PrinterList.Name -Like "P0"}
like image 853
AMIGA Avatar asked Jan 26 '26 08:01

AMIGA


1 Answers

Per the other answer, you need to include one or more wildcard characters in your string (e.g * for 0 or more characters, or ? for a single character).

You can also simplify your code to use a wildcard in the -Name parameter on the cmdlet directly:

$PrinterList = Get-Printer -ComputerName "PrintServer" -Name "P0*"
like image 163
Mark Wragg Avatar answered Jan 29 '26 08:01

Mark Wragg