1
votes

Hi I was trying to filter by printer name in work environment which I need to filter by name.

Get-printer function result is:

Name                           ComputerName    Type         DriverName                PortName        Shared   Published  DeviceType
----                           ------------    ----         ----------                --------        ------   ---------  ----------
Fax (redirected 2)                             Local        Microsoft Shared Fax D... TS011           False    False      Print
Microsoft XPS Document Writ...                 Local        Microsoft XPS Document... TS012           False    False      Print
Microsoft Print to PDF (red...                 Local        Microsoft Print To PDF    TS002           False    False      Print
Microsoft XPS Document Writer                  Local        Microsoft XPS Document... PORTPROMPT:     False    False      Print
Microsoft Print to PDF                         Local        Microsoft Print To PDF    PORTPROMPT:     False    False      Print

There is no parameter as 'Like':

Get-Printer -Like "Microsoft'"

Get-Printer : A parameter cannot be found that matches parameter name 'Like'. At line:1 char:13

Can anyone tell me how to retrieve all the printers start with name 'Microsoft'?

2

2 Answers

1
votes

Get-Printer can actually accept a wildcard for the Name parameter.

So to retrieve printers that start Microsoft you just add a * wildcard to the name like this:

Get-Printer -Name Microsoft*
1
votes

If you are using PowerShell, you can use where (Where-Object) clause, in your case it would look like:

Get-Printer | where {$_ -match 'Microsoft'}

Then you can get filtered table of printers, if you need to get array of names it would be:

(Get-Printer).name | where {$_ -match 'Microsoft'}