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"}
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*"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With