If you stare at this long enough, you will eventually feel the urge to stab yourself in the eyes with a plastic spork.  Repeatedly.  But it does work, as far as I’ve tested.

Rather than copy/paste version tables into arrays, or flat files, and deal with future updates, I thought it might be better to just hook my engine up to the neighbors power feed and let them handle the bill.  Wait a minute, that’s not what I really mean.  I mean, connect the lookup directly to a “trusted” publicly-available, published report (i.e. TechNet).  I’m SURE this can be done more efficiently using another approach (DOM?) so if you have suggestions, please post a comment below?  Thank you!

UPDATE 8/15/2016 – There was a line missing in the script code (e.g. “$guts = $site.Content”).  Thanks to Dan Gough for informing me of this!

UPDATE:  Just a few comments… I wanted to use GetElementByTag or something more structured, but the table wrapper inside that URL doesn’t use a class or object ID of any kind.  It’s just a generic HTML table.  Same with the TR and TD row/cell delineations.  There’s no exception handling either, so this is like a car without brakes and a pair of vice grips for a steering wheel.


Example: .\Get-WebScrapeCmFullVersionName.ps1 -Version “5.00.7958.1203”

Returns: “ConfigMgr 2012 R2 CU1”

function Get-CmFullVersionName {
  param (
  $weburl = "https://blogs.technet.microsoft.com/configmgrdogs/2014/02/07/configmgr-2012-version-numbers/"

  $site  = Invoke-WebRequest -UseBasicParsing -Uri $weburl
  $start = $site.Content.IndexOf("<tbody>") + 7
  $end   = $site.Content.IndexOf("</tbody>")
  $guts  = $site.Content
  $tablecontents = $guts.substring($start, $end-$start)

  $newtable = $tablecontents.Replace("<tr>","|")
  $newtable = $newtable.Replace("</tr>`n","")
  $newtable = $newtable.Replace("<td width=`"173`" valign=`"top`">","")
  $newtable = $newtable.Replace("<td width=`"128`" valign=`"top`">",",")
  $newtable = $newtable.Replace("<td width=`"98`" valign=`"top`">",",")
  $newtable = $newtable.Replace("</td>","")
  $newtable = $newtable.Replace("<p>","")
  $newtable = $newtable.Replace("</p>","")
  $newtable = $newtable.Replace("`n","")

  $rows = $newtable.split("|")
  $result = ""

  foreach ($row in $rows) {
    $cells = $row.Split(",")
    if ($cells[1] -eq $VersionNumber) {
      $result = $cells[0]
  return $result


3 thoughts on “Tragic PowerShell – Web Scrape ConfigMgr Version Lookups

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s