{"id":4118,"date":"2014-11-07T11:05:42","date_gmt":"2014-11-07T16:05:42","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=4118"},"modified":"2014-11-14T11:26:06","modified_gmt":"2014-11-14T16:26:06","slug":"friday-fun-im-with-the-band","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4118\/friday-fun-im-with-the-band\/","title":{"rendered":"Friday Fun: I&#8217;m with the band."},"content":{"rendered":"<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/11\/black-guitar.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-thumbnail wp-image-4119\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/11\/black-guitar-150x150.png\" alt=\"black-guitar\" width=\"150\" height=\"150\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/11\/black-guitar-150x150.png 150w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/11\/black-guitar.png 288w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/a>I like to have fun with PowerShell, as is hopefully evident with this Friday Fun serious, and today that is especially true. Perhaps you need a quick break from the end of the week grind. Or maybe you want to learn something new about PowerShell. Hopefully today's fun will meet both requirements. Today's fun will include XML, scope and Switch. Let's rock.<\/p>\n<p>If you haven't figured it out, rock 'n roll is the theme for today. I have put together a little rock and roll quiz. In many rock bands there's at least one member is well known. If someone says \"Axl Rose\" you most likely will know Guns n' Roses. But would you recognize the other members of the band? I created an XML document with a number of well known rock bands. Because band members change, I tried to use the line ups from the bands peak years. If you want to play you will need to download <a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/11\/BandData.txt\">BandData.xml<\/a>. Save as an XML file to same directory as the script, which I'll show you in a moment. Try not to peek too much at the contents. This is the structure.<\/p>\n<pre class=\"lang:xhtml decode:true \" >&lt;Bands&gt;\r\n  &lt;Band&gt;\r\n    &lt;Name&gt;&lt;\/Name&gt;\r\n    &lt;Lead&gt;&lt;\/Lead&gt;\r\n    &lt;Members&gt;\r\n      &lt;Member&gt;&lt;\/Member&gt;\r\n      &lt;Member&gt;&lt;\/Member&gt;\r\n    &lt;\/Members&gt;\r\n  &lt;\/Band&gt;\r\n&lt;\/Bands&gt;<\/pre>\n<p>My quiz is a PowerShell script that processes the data in the XML document. It will display a list of band members, without the recognizable lead and multiple choice of possible bands. After answering the questions you will be judged, I mean graded.<\/p>\n<pre class=\"lang:ps decode:true \" >\r\n#BandQuiz.ps1\r\n\r\nParam($Questions = 10)\r\n\r\n$file = '.\\BandData.xml'\r\n[xml]$data = Get-Content $file\r\n\r\n#get all of the band names\r\n$bandNames = $data.Bands.Band.name\r\n\r\n#select 10 random entries\r\n$testdata =  $data.Bands.band | Get-Random -Count $Questions\r\n\r\n#initialize some counter variables that will be updated from a different scope\r\n$script:i = 0\r\n$script:q = 0\r\n\r\n#process each one\r\nforeach ($band in $testdata) {\r\n\r\n    #build a list of band names\r\n    $answer = $band.name\r\n    $Choices = $bandNames | where {$_ -ne $answer} | Get-Random -count 3\r\n    $Choices+= $answer\r\n\r\n    #sort names and create a hashtable using a number as the key\r\n    $bandhash = @{}\r\n    $choices | Sort | foreach -begin {$K=1} -process {\r\n      $bandhash.Add($K,$_)\r\n      $K++\r\n    }\r\n   \r\n    #get band members as a string list\r\n    $members = ($band.members | select -expand member | Format-List | Out-String).Trim()\r\n\r\n    #prompt\r\n    #use a scriptblock as an ad-hoc function\r\n$promptblock = {\r\nParam([string]$Lead)\r\n\r\nif ($lead) {$leadmember = \"*$lead*`n\"}\r\n#cls\r\n$script:Q++\r\n\r\n#define a here string to be used for the prompt\r\n$prompt=@\"\r\nQuestion: $script:Q\r\n\r\n$members\r\n$leadmember\r\nWhat band do these people belong to?\"\r\n\r\n$(($bandHash.GetEnumerator() | Sort Name | out-string).trim())\r\n\r\nEnter a number or 0 to see the lead band member\r\n\"@\r\n\r\n    [int]$r = Read-Host -Prompt $prompt\r\n\r\n    #check result\r\n    if ($r -eq 0) {\r\n      $Band.lead\r\n      #decrement question counter since we're repeating\r\n      $script:Q--\r\n      #re-run the prompt scriptblock to include the lead member\r\n      &amp;$promptblock -lead $band.Lead\r\n    }\r\n    elseif ($bandhash.$r -eq $answer) {\r\n        Write-Host \"Correct!\" -ForegroundColor green\r\n        #record result\r\n        $script:i++\r\n    }\r\n    else {\r\n        Write-Host \"Incorrect\" -ForegroundColor red\r\n    }\r\n} #close promptblock\r\n &amp;$promptblock\r\n}\r\n\r\n#display results\r\n[int]$correct = ($i\/$Questions) * 100\r\n\r\nSwitch ($correct) {\r\n{$_ -ge 90} {$quip = \"You are a juke box hero.\" ; break}\r\n{$_ -ge 75} {$quip = \"You're bad to the bone.\" ; break}\r\n{$_ -ge 50} {$quip = \"It's a long way to the top if you wanna rock 'n roll.\" ; break}\r\n{$_ -ge 25} {$quip = \"Another one bites the dust.\" ; break}\r\n\r\ndefault {$quip = \"Stick to Mantovani.\"}\r\n\r\n}\r\n\r\n\"`nYou got {0:P0} correct. {1}\" -f ($i\/$Questions),$Quip\r\n<\/pre>\n<p>Let's look at a few key points of the script. <\/p>\n<p>First, I need to load the XML document.<\/p>\n<pre class=\"lang:ps decode:true \" >$file = '.\\BandData.xml'\r\n[xml]$data = Get-Content $file<\/pre>\n<p>The [XML] type accelerator will create an XML document. When you have an XML document in PowerShell, each node can be treated like a property so it is very easy to navigate or get values, like a list of all the band names.<\/p>\n<pre class=\"lang:ps decode:true \" >$bandNames = $data.Bands.Band.name\r\n<\/pre>\n<p>The script then selects a random number of band entries from the XML document. These will be the basis of the quiz. For each item I create a list of band choices and band members that will be displayed. You'll also noticed that I initialize some counters with the $script prefix.<\/p>\n<pre class=\"lang:ps decode:true \" >$script:i = 0\r\n$script:q = 0<\/pre>\n<p>Here's why. I am using a scriptblock, defined as $promptblock, to display each question and keep track of correct answers. The scriptblock runs in a new scope, or container. That means when it tries to do something with a variable like $Q it first looks in the current scope for that item. If it finds it, it uses it. Otherwise PowerShell searches up the scope hierarchy to the parent scope looking for the item. But here's what trips people up. If you are only reading, like I am, for things like the $bandhash object, PowerShell will happily find it in the parent scope and display it. But when I try to modify a variable like $Q or $i it can only modify it in the current scope. But I need to use those variables outside of the scriptblock scope, so I preface the variable with $Script: to indicate the scope level for those variables. The general rule is to not reference out-of-scope variables, but since I'm using $script: I'm telling PowerShell I know what I'm doing.<\/p>\n<p>After running through all the questions, the script can calculate how many correct answers you had and present a score card. I decided to use a Switch statement to assist.<\/p>\n<pre class=\"lang:ps decode:true \" >Switch ($correct) {\r\n{$_ -ge 90} {$quip = \"You are a juke box hero.\" ; break}\r\n{$_ -ge 75} {$quip = \"You're bad to the bone.\" ; break}\r\n{$_ -ge 50} {$quip = \"It's a long way to the top if you wanna rock 'n roll.\" ; break}\r\n{$_ -ge 25} {$quip = \"Another one bites the dust.\" ; break}\r\n\r\ndefault {$quip = \"Stick to Mantovani.\"}\r\n\r\n}<\/pre>\n<p>Normally in a Switch you would use a simple value. But you can also use PowerShell expressions. In my Switch statement, if the value of $Correct is >= 90, then I assign a certain value to $quip. When using expressions, use $_. Remember that Switch will process every matching expression and since I don't want that, I'm using the Break keyword so PowerShell knows not to keep checking the other possibilities.<\/p>\n<p>When you run the quiz, you will get an item like this:<br \/>\n<a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/11\/bandquiz-1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/11\/bandquiz-1-1024x561.png\" alt=\"bandquiz-1\" width=\"474\" height=\"259\" class=\"aligncenter size-large wp-image-4123\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/11\/bandquiz-1-1024x561.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/11\/bandquiz-1-300x164.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/11\/bandquiz-1.png 1122w\" sizes=\"auto, (max-width: 474px) 100vw, 474px\" \/><\/a><\/p>\n<p>The display is from the prompt scriptblock. If you need a little help, enter 0 which re-displays the question this time with the (hopefully) more recognizable lead.<\/p>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/11\/bandquiz-2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/11\/bandquiz-2-1024x542.png\" alt=\"bandquiz-2\" width=\"474\" height=\"250\" class=\"aligncenter size-large wp-image-4124\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/11\/bandquiz-2-1024x542.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/11\/bandquiz-2-300x158.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/11\/bandquiz-2.png 1126w\" sizes=\"auto, (max-width: 474px) 100vw, 474px\" \/><\/a><\/p>\n<p>And the final snarky commentary on your rock knowledge.<br \/>\n<a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/11\/bandquiz-3.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/11\/bandquiz-3-1024x580.png\" alt=\"bandquiz-3\" width=\"474\" height=\"268\" class=\"aligncenter size-large wp-image-4125\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/11\/bandquiz-3-1024x580.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/11\/bandquiz-3-300x170.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/11\/bandquiz-3.png 1092w\" sizes=\"auto, (max-width: 474px) 100vw, 474px\" \/><\/a><\/p>\n<p>Because I am of a certain age, the contents of my band data xml file might be slightly skewed. If you were born after 1985 you might have some problems. <\/p>\n<p>I think XML files scare some IT Pros but they really aren't that difficult to work with once you understand some basics. In fact, I'll be coming back to my band xml file in future posts. In the mean time, party on and let me know if you have any questions about my quiz script.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I like to have fun with PowerShell, as is hopefully evident with this Friday Fun serious, and today that is especially true. Perhaps you need a quick break from the end of the week grind. Or maybe you want to learn something new about PowerShell. Hopefully today&#8217;s fun will meet both requirements. Today&#8217;s fun will&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"New from the blog-> Friday Fun: I'm with the band.","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[271,4,8],"tags":[534,469,540,206],"class_list":["post-4118","post","type-post","status-publish","format-standard","hentry","category-friday-fun","category-powershell","category-scripting","tag-powershell","tag-scope","tag-scripting","tag-xml"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Friday Fun: I&#039;m with the band. &#8226; The Lonely Administrator<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/4118\/friday-fun-im-with-the-band\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Friday Fun: I&#039;m with the band. &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"I like to have fun with PowerShell, as is hopefully evident with this Friday Fun serious, and today that is especially true. Perhaps you need a quick break from the end of the week grind. Or maybe you want to learn something new about PowerShell. Hopefully today&#039;s fun will meet both requirements. Today&#039;s fun will...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/4118\/friday-fun-im-with-the-band\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2014-11-07T16:05:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-11-14T16:26:06+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/11\/black-guitar-150x150.png\" \/>\n<meta name=\"author\" content=\"Jeffery Hicks\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:site\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeffery Hicks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/4118\\\/friday-fun-im-with-the-band\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/4118\\\/friday-fun-im-with-the-band\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Friday Fun: I&#8217;m with the band.\",\"datePublished\":\"2014-11-07T16:05:42+00:00\",\"dateModified\":\"2014-11-14T16:26:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/4118\\\/friday-fun-im-with-the-band\\\/\"},\"wordCount\":777,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/4118\\\/friday-fun-im-with-the-band\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2014\\\/11\\\/black-guitar-150x150.png\",\"keywords\":[\"PowerShell\",\"scope\",\"Scripting\",\"xml\"],\"articleSection\":[\"Friday Fun\",\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/4118\\\/friday-fun-im-with-the-band\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/4118\\\/friday-fun-im-with-the-band\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/4118\\\/friday-fun-im-with-the-band\\\/\",\"name\":\"Friday Fun: I'm with the band. &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/4118\\\/friday-fun-im-with-the-band\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/4118\\\/friday-fun-im-with-the-band\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2014\\\/11\\\/black-guitar-150x150.png\",\"datePublished\":\"2014-11-07T16:05:42+00:00\",\"dateModified\":\"2014-11-14T16:26:06+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/4118\\\/friday-fun-im-with-the-band\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/4118\\\/friday-fun-im-with-the-band\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/4118\\\/friday-fun-im-with-the-band\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2014\\\/11\\\/black-guitar.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2014\\\/11\\\/black-guitar.png\",\"width\":288,\"height\":288},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/4118\\\/friday-fun-im-with-the-band\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Friday Fun\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/friday-fun\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Friday Fun: I&#8217;m with the band.\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/\",\"name\":\"The Lonely Administrator\",\"description\":\"Practical Advice for the Automating IT Pro\",\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\",\"name\":\"Jeffery Hicks\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"caption\":\"Jeffery Hicks\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Friday Fun: I'm with the band. &#8226; The Lonely Administrator","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4118\/friday-fun-im-with-the-band\/","og_locale":"en_US","og_type":"article","og_title":"Friday Fun: I'm with the band. &#8226; The Lonely Administrator","og_description":"I like to have fun with PowerShell, as is hopefully evident with this Friday Fun serious, and today that is especially true. Perhaps you need a quick break from the end of the week grind. Or maybe you want to learn something new about PowerShell. Hopefully today's fun will meet both requirements. Today's fun will...","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4118\/friday-fun-im-with-the-band\/","og_site_name":"The Lonely Administrator","article_published_time":"2014-11-07T16:05:42+00:00","article_modified_time":"2014-11-14T16:26:06+00:00","og_image":[{"url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/11\/black-guitar-150x150.png","type":"","width":"","height":""}],"author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4118\/friday-fun-im-with-the-band\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4118\/friday-fun-im-with-the-band\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Friday Fun: I&#8217;m with the band.","datePublished":"2014-11-07T16:05:42+00:00","dateModified":"2014-11-14T16:26:06+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4118\/friday-fun-im-with-the-band\/"},"wordCount":777,"commentCount":1,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4118\/friday-fun-im-with-the-band\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/11\/black-guitar-150x150.png","keywords":["PowerShell","scope","Scripting","xml"],"articleSection":["Friday Fun","PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/4118\/friday-fun-im-with-the-band\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4118\/friday-fun-im-with-the-band\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4118\/friday-fun-im-with-the-band\/","name":"Friday Fun: I'm with the band. &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4118\/friday-fun-im-with-the-band\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4118\/friday-fun-im-with-the-band\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/11\/black-guitar-150x150.png","datePublished":"2014-11-07T16:05:42+00:00","dateModified":"2014-11-14T16:26:06+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4118\/friday-fun-im-with-the-band\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/4118\/friday-fun-im-with-the-band\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4118\/friday-fun-im-with-the-band\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/11\/black-guitar.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/11\/black-guitar.png","width":288,"height":288},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4118\/friday-fun-im-with-the-band\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Friday Fun","item":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},{"@type":"ListItem","position":2,"name":"Friday Fun: I&#8217;m with the band."}]},{"@type":"WebSite","@id":"https:\/\/jdhitsolutions.com\/blog\/#website","url":"https:\/\/jdhitsolutions.com\/blog\/","name":"The Lonely Administrator","description":"Practical Advice for the Automating IT Pro","publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jdhitsolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9","name":"Jeffery Hicks","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","caption":"Jeffery Hicks"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":1011,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell-v2-0\/1011\/friday-fun-quote-of-the-day\/","url_meta":{"origin":4118,"position":0},"title":"Friday Fun Quote of the Day","author":"Jeffery Hicks","date":"November 5, 2010","format":false,"excerpt":"For this week's Friday Fun post, I have another idea on how to brighten your PowerShell console. The concept of a message of the day or quote of the day in computing goes way back to the dark ages (ie before PowerShell). I thought it might be fun to see\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/11\/qotd.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/11\/qotd.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/11\/qotd.png?resize=525%2C300 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/11\/qotd.png?resize=700%2C400 2x"},"classes":[]},{"id":4332,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4332\/friday-fun-open-last-file-in-the-powershell-ise\/","url_meta":{"origin":4118,"position":1},"title":"Friday Fun: Open Last File in the PowerShell ISE","author":"Jeffery Hicks","date":"March 27, 2015","format":false,"excerpt":"Over the last few articles I've been sharing some shortcuts to get most recently used or edited files. For today's Friday Fun I thought I'd share something that I use in my PowerShell ISE profile. Whenever I start the ISE, I automatically open the last file I was working on.\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":8400,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8400\/friday-fun-custom-grouping-with-powershell\/","url_meta":{"origin":4118,"position":2},"title":"Friday Fun &#8211; Custom Grouping with PowerShell","author":"Jeffery Hicks","date":"May 14, 2021","format":false,"excerpt":"The other day I was answering a question in the PowerShell Facebook group. This person was getting data from Active Directory and trying to organize the results in a way that met his business requirements. My suggestion was to use Group-Object and a custom grouping property. I am assuming you\u2026","rel":"","context":"In &quot;Active Directory&quot;","block_context":{"text":"Active Directory","link":"https:\/\/jdhitsolutions.com\/blog\/category\/active-directory\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/custom-grouping.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/custom-grouping.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/custom-grouping.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/custom-grouping.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":3140,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/3140\/friday-fun-quote-of-the-day-revised\/","url_meta":{"origin":4118,"position":3},"title":"Friday Fun: Quote of the Day Revised","author":"Jeffery Hicks","date":"June 28, 2013","format":false,"excerpt":"This week TrainSignal has been running a contest to celebrate my new PowerShell 3.0 course . All you have to do to win is enter some off-the-wall, silly or non-production use of PowerShell. I've posted a few examples on the TrainSignal blog this week. \u00a0These Friday Fun posts I write\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"talkbubble-v3","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/05\/talkbubble-v3-150x150.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":4184,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4184\/friday-fun-search-me\/","url_meta":{"origin":4118,"position":4},"title":"Friday Fun: Search Me","author":"Jeffery Hicks","date":"January 16, 2015","format":false,"excerpt":"I've been working on a few revisions and additions to my ISE Scripting Geek module. Even though what I'm about to show you will eventually be available in a future release of that module, I thought I'd share it with you today. One of the things I wanted to be\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"magnifying-glass-text-label-search","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/01\/magnifying-glass-text-label-search-150x150.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":4895,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4895\/friday-fun-a-sysinternals-powershell-workflow\/","url_meta":{"origin":4118,"position":5},"title":"Friday Fun: A SysInternals PowerShell Workflow","author":"Jeffery Hicks","date":"February 12, 2016","format":false,"excerpt":"Over the years I've come up with a number of PowerShell tools to download the SysInternals tools to my desktop. And yes, I know that with PowerShell 5 and PowerShellGet I could download and install a SysInternals package. But that assumes the package is current.\u00a0 But that's not really the\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"image","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/02\/image_thumb-5.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/02\/image_thumb-5.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/02\/image_thumb-5.png?resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/4118","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=4118"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/4118\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=4118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=4118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=4118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}