How I used PowerShell “CTP2” to make my manager happier

This is a follow up to my original post “How I used PowerShell to make my manager happy”, with some updated information. The original post and code was based on V1.0 or PowerShell, however when moving to a CTP of V2, the Community extensions no longer work. Which means the all important line

$details = Split-String $row -Separator " "

will not break the rows up for me and enable me to extract the ID. The good news is that the “SPLIT” function is now native in V2, so my new line is now

$details = $row -Split " "

This change gives me the desired effect and there are no other changes needed to make the script work.

However, on a general note I’ve also been send a improvement to the script by Lee Holmes. Lee points out that I can replace these lines

if ($row -match "SessionDetails")
   {
if ($row -match "GET")
{
if ($row -match " 200 ")

$details = Split-String $row -Separator " "
$ID = $details[6].Substring($details[6].LastIndexOf("=")+1)

With this one line

(gc $file.FullName) | ? { $_ -match "^.*GET .*SessionDetails.*&id=(?<Id>.*) 200" } | % { $matches.Id }

Lee pointed out to me that The match operator supports full-on regular expressions as well as supporting named captures letting me extract out the ID automatically into the $matches variable: https://www.leeholmes.com/blog/RegularExpressionsInMonad.aspx

I can now pass $matches.ID to the Select-XML function to retrieve my Content page title.

Thank you Lee.