FogBugz user, Berounský Václav, offered up this PowerShell script which validates your currently installed version of FogBugz against the latest available version (as published on shop.fogcreek.com).
Note: This script was contributed by a third party, not Fog Creek Software, and it has not been tested for functionality or security.
# Check-FogBugzVersion.ps1
# 2010 Rebex CR # www.rebex.net<http://www.rebex.net> # support@rebex.cz<mailto:support@rebex.cz>
# Windows PowerShell Script # Output ready for PolyMon
# FogBugz URL
[string]$FogBugzUrl = "http://fogbugz.domain.com"
[string]$FogBugzPattern = '<a href="http://www.fogcreek.com/FogBugz">FogBugz</a> Version .*'
# FogCreek URL
[string]$FogCreekUrl = "https://shop.fogcreek.com/FogBugz/download.asp?cmd=fbupgrade"
[string]$FogCreekPattern = '<p>The current version is.*'
# Counter definition
[string]$CounterDescriptionDB = "FogBugzVersion"
# PowerShell Debug variables
# Clear-Host
$Status = @{}
$Status.StatusID = $null
$Status.StatusText = $null
$Counters = @{}
# Main()
# Default status
$Status.StatusText = "Fail. Unknown reason"
$Status.StatusID = 3
$CounterValue = $null
function Get-UrlContent (
$url = $(throw "Empty value for the URL parameter.")
) {
$request = [System.Net.HttpWebRequest]::Create($url);
$response = $request.GetResponse();
$encoding = [System.Text.Encoding]::GetEncoding( $response.CharacterSet )
[string]$output = ""
if ($response.StatusCode -ne 200) {
return $null
} else {
# Get WEB
[int]$goal = $response.ContentLength
$reader = $response.GetResponseStream()
[byte[]]$buffer = new-object byte[] 4096
[int]$count = 0
do {
$count = $reader.Read($buffer, 0, $buffer.Length);
$output += $encoding.GetString($buffer,0,$count)
} while ($count -gt 0)
$reader.Close()
return $output
}
}
# FogBugz URL
if ( $(Get-UrlContent($FogBugzUrl)) -match $FogBugzPattern) {
$FogBugzVersion = $Matches[0].Split('&')[1] -replace "nbsp;"
} else {
$FogBugzVersion = $null
}
# FogCreek URL
if ( $(Get-UrlContent($FogCreekUrl)) -match $FogCreekPattern) {
$FogCreekVersion = $Matches[0].Split(' ')[4] -replace "\.$"
} else {
$FogCreekVersion = $null
}
# Results of FogCreekVersion Vs FogBugzVersion
if (($FogCreekVersion -gt $FogBugzVersion) -or ($FogCreekVersion -eq $null) -or ($FogBugzVersion -eq $null)) {
$Status.StatusText = "Fail. Unable to get version or You have version " + $FogBugzVersion + " and the new version " + $FogCreekVersion + " is available"
$Status.StatusID = 3
$CounterValue = 1
} else {
$Status.StatusText = "You have the latest version " + $FogBugzVersion
$Status.StatusID = 1
$CounterValue = 0
}
# PolyMon.Counter.Add
$Counters.Add($CounterDescriptionDB, $CounterValue)
# PowerShell Debug variables
$Status.StatusText
$Status.StatusID
$error