Use Comparison Operators for Logfile Parsing

by Dec 24, 2012

Comparison operators usually return either $true or $false, but when applied to an array, return the array elements that match the comparison. You can use this to easily parse text-based logfile information.

This simple line returns all updates installed on a machine, parsed out of the raw text-based logfile windowsupdate.log:

(Get-Content -Path $env:windir\windowsupdate.log -ReadCount 0 -Encoding UTF8) -like '*successfully installed*' | 
  ForEach-Object { ($_ -split ': ')[-1] }

Twitter This Tip! ReTweet this Tip!