Reputation: 33
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"}
Upvotes: 3
Views: 7110
Reputation: 23355
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*"
Upvotes: 2
Reputation: 20237
You need a wildcard for your -like
, e.g. name -like 'P0*'
This should work with both of your solutions.
Upvotes: 1