I was recently recording a webcast for Connections Online about using PowerShell with SharePoint, and I put together what I think it a pretty cool four lines of code:
$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
$bv = $farm.BuildVersion.ToString()
$vertable = Import-Csv versions.csv
$vertable | where-object {$_.Version -eq $bv}
A sample versions.csv file is here: http://blumenthalit.net/Files/PowerShell%20Scripts/versions.csv
What the last line of the script returns is a description of the version (e.g. “April CU”) plus the corresponding WSS and MOSS KB articles IDs.
Part of the beauty of this is that I didn’t have to do anything complex to store my data – it took me just a few minutes to create my csv file by hand, and I didn’t have to deal with parsing it, or with picking a collection datatype (List, HashTable, etc) to store it in. Import-CSV, which is a cmdlet that ships with PowerShell v1.0 did all that for me.
You can download the script file here: Get-sharepointversion.ps1 (put it in the same folder as the CSV file).
One of these days, I should move that into CodePlex.com/PSBB, but not today.
Michael