Getting Installed Updates

by Jun 24, 2010

PowerShell is great for parsing log files. Here is a function that extracts all installed Windows updates from an internal log file and returns the information as pure PowerShell objects. Have a look as this code uses a number of powerful parsing and wrapping techniques:

function Get-Updates {
Get-Content $env:windirwindowsupdate.log -encoding utf8 |
Where-Object { $_ -like '*successfully installed*'} |
ForEach-Object {
$info = $_.Split("`t")
$hash = @{}
$hash.InstallDate = [DateTime]$info[6].Remove($info[6].LastIndexOf(":"))
$hash.Product = $info[1].Split(":")[1].Trim()
New-Object PSobject -property $hash
}
}

Get-Updates