munish
munish

Reputation: 4654

How to filter the output from the output of this powershell command?

Get-WinEvent -FilterHashTable @{LogName="Microsoft-Windows-PrintService/Operational";} |
Format-Table -Property TimeCreated,
                        @{label='UserName';expression={$_.properties[2].value}},
                        @{label='ComputerName';expression={$_.properties[3].value}},
                        @{label='PrinterName';expression={$_.properties[4].value}},
                        @{label='PrintSize';expression={$_.properties[6].value}},
                        @{label='Pages';expression={$_.properties[7].value}} 

I want to filter out all those lines where PrinterName is "MyPrinter" from the output of the above command

Upvotes: 1

Views: 242

Answers (1)

Martin Brandl
Martin Brandl

Reputation: 59001

Just add a Where-Object condition before you format the table:

Get-WinEvent -FilterHashTable @{LogName="Security";} | 
    Where-Object { $_.properties[4].value -eq 'MyPrinter'} | 
    Format-Table -Property TimeCreated,
        @{label='UserName';expression={$_.properties[2].value}},
        @{label='ComputerName';expression={$_.properties[3].value}},
        @{label='PrinterName';expression={$_.properties[4].value}},
        @{label='PrintSize';expression={$_.properties[6].value}},
        @{label='Pages';expression={$_.properties[7].value}} 

Upvotes: 3

Related Questions