{"id":7638,"date":"2020-08-07T11:51:45","date_gmt":"2020-08-07T15:51:45","guid":{"rendered":"https:\/\/jdhitsolutions.com\/blog\/?p=7638"},"modified":"2020-09-30T16:44:25","modified_gmt":"2020-09-30T20:44:25","slug":"friday-fun-a-powershell-nonsense-challenge","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7638\/friday-fun-a-powershell-nonsense-challenge\/","title":{"rendered":"Friday Fun &#8211; A PowerShell Nonsense Challenge"},"content":{"rendered":"\n<p>Today I thought I'd share my PowerShell solution to a recent Iron Scripter <a href=\"https:\/\/ironscripter.us\/a-powershell-nonsense-challenge\" target=\"_blank\" rel=\"noopener noreferrer\">challenge<\/a>. The challenge was to create PowerShell code that would create nonsense documents, with a goal of creating 10 sample files filled with gibberish. Yes, other than maybe wanting some test files to work with, on its face the challenge appears pointless.&nbsp; However, as with all of these challenges, or even the ones in <a href=\"https:\/\/leanpub.com\/psprimer\" target=\"_blank\" rel=\"noopener noreferrer\">The PowerShell Practice Primer,<\/a> the journey is the reward. The true value is learning how to use PowerShell, and maybe discovering a new technique or command. The hope is that during the course of working on the challenge, you'll improve your PowerShell scripting skills. And who knows, maybe even have a little fun along the way.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Nonsense Documents<\/h2>\n\n\n\n<p>I've put everything in a module on Github called <a href=\"https:\/\/github.com\/jdhitsolutions\/PSNonsense\" target=\"_blank\" rel=\"noopener noreferrer\">PSNonsense<\/a>.<\/p>\n\n\n\n<p>I approached this in a building block approach. I begin with a function to create a nonsense word. This is simple enough. All I need to do is select a number of random characters from a pool and join them together.<\/p>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">$letters = [Char[]]'abcdefghijklmnopqrstuvwxyz'\n  #add some diacritical characters\n  $letters += [Char]0x00EB,[Char]0x00E4,[Char]0x00E9\n\n  -join ( $letters | Get-Random -count $Length)\n<\/code><\/pre>\n\n\n\n<p>The function, as do all of the functions, includes parameters to define the length or count, using a random default. I also use a ValidateSet attribute to verify the parameter value a user might enter.<\/p>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">Param(\n    [Parameter(Position = 0, HelpMessage = \"Indicate the word length between 1 and 10.\")]\n    [ValidateRange(1, 10)]\n    [int]$Length = (Get-Random -Minimum 1 -Maximum 10)\n  )<\/code><\/pre>\n\n\n\n<p>Creating a nonsense word is this easy.<\/p>\n\n\n\n<pre class=\"wp-block-code lang:text mark:0 decode:true\"><code lang=\"bash\" class=\"language-bash\">PS C:\\> New-NonsenseWord -Length 7\n\u00ebfsw\u00e4na<\/code><\/pre>\n\n\n\n<p>A nonsense sentence is just a collection of nonsense words. But there was an additional challenge to insert punctuation and to make sure sentences ended in a period. I added code to randomly end some sentences in a question mark or exclamation point.<\/p>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">$punct = \", \", \"; \", \" - \", \": \"\n  #define a flag to indicate if random punctuation has been inserted.\n  $NoPunct = $true\n\n  1..($WordCount - 1) | ForEach-Object -Begin {\n    #make sure we start the sentence with a word\n    [string]$sentence = New-NonsenseWord\n  } -process {\n    #insert random punctuation into the sentence, but only once\n    if (($WordCount -ge 10) -AND (Test) -AND $NoPunct) {\n      $sentence += $punct | Get-Random -Count 1\n      $NoPunct = $False\n    }\n    $sentence += \"{0} \" -f (New-NonsenseWord)\n  }\n\n  #capitalize the first word of the sentence.\n  #does the sentence end in a period, exclamation or question mark.\n  #The period should be the default most of the time\n  $rn = Get-Random -Maximum 100 -Minimum 1\n  Switch ($rn) {\n    {$_ -ge 90} {$end = \"?\" ; break}\n    {$_ -ge 82} { $end = \"!\"}\n    Default { $end = \".\"}\n  }\n\n  $out = \"{0}{1}{2}\" -f ([string]$sentence[0]).ToUpper(), $sentence.substring(1).TrimEnd(),$end\n<\/code><\/pre>\n\n\n\n<p>The function includes a private function called Test which randomly determines if I should do something, like insert punctuation.<\/p>\n\n\n\n<pre class=\"wp-block-code lang:text mark:0 decode:true\"><code lang=\"bash\" class=\"language-bash\">PS C:\\&gt; New-NonsenseSentence -WordCount 11\nUrip; \u00e9lthe qkvipwen kym h f\u00e4uq cwuo\u00e9hjn\u00e4 ikafysqol eom ik\u00e4b yke.<\/code><\/pre>\n\n\n\n<p>Creating a paragraph means joining a specified number of sentences together.<\/p>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">$raw = 1..$SentenceCount | Foreach-object {New-NonsenseSentence}\n  ($raw -join \" \").trimend()\n<\/code><\/pre>\n\n\n\n<p>Since samples are getting a bit longer, here's a screen shot.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1314\" height=\"600\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/08\/nnp.png\" alt=\"nnp\" class=\"wp-image-7639\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/08\/nnp.png 1314w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/08\/nnp-300x137.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/08\/nnp-1024x468.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/08\/nnp-768x351.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/08\/nnp-850x388.png 850w\" sizes=\"auto, (max-width: 1314px) 100vw, 1314px\" \/><\/figure>\n\n\n\n<p>Notice the puncutation.<\/p>\n\n\n\n<p>Creating a document is nothing more than a collection of paragraphs.<\/p>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">#insert a return after each paragraph\n  1..$ParagraphCount | ForEach-Object {New-NonsenseParagraph;\"`r\"}\n<\/code><\/pre>\n\n\n\n<p>With this function, New-NonsenseDocument, I can use code like this to create 10 documents.<\/p>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">1..10 | ForEach-Object {\n    $filename = [System.IO.Path]::GetRandomFileName()\n    #replace the extension\n    $filename = $filename -replace \"\\.\\w+\", \".txt\"\n    #build the path\n    $path = Join-Path -path $env:TEMP -ChildPath $filename\n    #create the document\n    #encode as UTF8 to save the diacritical characters\n    New-NonsenseDocument -ParagraphCount (Get-Random -Minimum 3 -Maximum 10) | \n    Out-File -FilePath $path -Encoding utf8\n    #view the result\n    Get-Item $path\n}<\/code><\/pre>\n\n\n\n<p>I'm useing the .NET Framework to generate a randome file name and then using a regex pattern to replace the extension with .txt extension. The final file path is built using Join-Path which is recommended instead of trying to concatenate strings together. You can view the files in the Samples folder in the PSNonsense repository.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Markdown Nonsense<\/h2>\n\n\n\n<p>The challenge had an extra-credit requirement to create a nonsense markdown document. A markdown document has specific requirements for headings. Ultimately, I built the file by using a here-string, and inserting randomly generated markdown elements.<\/p>\n\n\n\n<p>To simplify things (honestly), I wrapped the PSNonsense commands into a few helper, or cheater, functions.<\/p>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">function New-Heading {\n    (New-NonsenseSentence -WordCount (Get-Random -Minimum 1 -Maximum 5)) -replace \"[.!?]\", \"\"\n}\n\nfunction New-CodeFence {\n    $cmd = \"$((New-NonsenseSentence -WordCount (Get-Random -Minimum 2 -Maximum 6)) -replace \"[.!?]\",'')\"\n\n    #the backtick needs to be escaped so that end result is a proper markdown code fence.\n    #there should be 6 backticks.\n    $cf = @\"\n$('`'*6)powershell\nPS C:\\&gt; $cmd\n$('`'*6)\n\"@\n    $cf\n}\n\nfunction New-SubHead {\n    Param(\n        [int]$Level = 2\n    )\n\n    $h = \"#\"*$level\n    $head = \"{0} {1}\" -f $h, (New-Heading)\n    #write-host $head -ForegroundColor red\n    $out = @\"\n$head\n\n\n\"@\n\n    1..(Get-Random -Maximum 4) | ForEach-Object {\n\n        $p = (New-NonsenseParagraph -SentenceCount (Get-Random -Minimum 4 -Maximum 10) -outvariable pv)\n\n        if ((Get-Random)%3) {\n            #randomly format a string\n            $wds = ($p.split()).where( {$_ -match \"\\w+\"})\n            $hl = $wds | Select-Object -skip (Get-Random -Minimum 7 -Maximum ($wds.count - 20)) -First (Get-Random -Minimum 1 -Maximum 7)\n\n            #randomly decide how to format\n            Switch ((Get-Random)) {\n                {$_%3} {$f = \"*$($hl -join \" \")*\" }\n                {$_%5} {$f = \"__$($hl -join \" \")__\"}\n                {$_%7} {$f = \"__*$($hl -join \" \")*__\" }\n                {$_%4} {$f = \"``$($hl -join \" \")``\" }\n                {$_%2} {$f = \"[$($hl -join \" \")](https:\/\/www.$(New-NonsenseWord).com)\"}\n            }\n            #left justify to send to the here string to avoid extra spaces\n            $out += ($p -replace ($hl -join \" \"), $f)\n        } #if %3\n        else {\n            $out += $p\n        }\n\n        $out += \"`n`n\"\n\n        &lt;#\n        the out variable is itself an array. I want to get the first item in that array,\n        which will be a string and then the first character in that string.\n        #&gt;\n        if ($pv[0][0] -match \"[aeifuylm]\") {\n            #$out+=\"`n\"\n            #increment if the next level is 4 or less\n            if ($level + 1 -le 4) {\n                $out += New-SubHead -level ($level + 1)\n            }\n            else {\n                #repeat the level\n                $out += New-SubHead -level $level\n            }\n        }\n        elseif ($pv[0][0] -match \"[pjqrst]\" ) {\n\n            $out += New-CodeFence\n            $out += \"`n`n\"\n            #add a bit more verbiage\n            $out += New-NonsenseParagraph -SentenceCount (Get-Random -Minimum 1 -Maximum 4)\n        }\n    } #foreach object\n\n    $out\n\n} #New-SubHead<\/code><\/pre>\n\n\n\n<p>I gave myself even more of a challenge by randomly inserting code fence sections, and formatting random phrases. I think the comments in the functions explain my thought process. With these functions, and my PSNonsense module, I can run code like this to create a nonsense markdown document.<\/p>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">$md = @\"\n# $(New-Heading)\n\n$((New-SubHead).trimend())\n\n__My additional New-Headings follow.__\n\n\n\"@\n\n1..(Get-Random -maximum 5) | ForEach-Object {\n    $md += New-SubHead\n}\n\n$md += \"Updated *$(Get-Date)*.\"\n\n$md\n#encode as UTF8 to save the diacritical characters\n$md | Out-File -FilePath c:\\work\\nonsense.md -Encoding utf8\n<\/code><\/pre>\n\n\n\n<p>The here-strings include the necessary blank lines to create a proper markdown document. Note the message about file encoding. If you use special characters and don't specify UTF8, the file might have '?' characters in place. One thing I noticed in VS Code is that in editor mode the markdown document is fine. But when I use the preview mode, it doesn't detect the special characters. I don't iknow if it is a bug or a setting I haven't found yet. Regardless, you can find my nonsense markdown and a PDF version in the Samples folder on Github.<\/p>\n\n\n\n<p>I hope you'll take some time to look at code in the module's repository. Ideally, you'll try it out yourself to see how it works and why. If you learn something new, I hope you'll let me know.<\/p>\n\n\n\n<p>In the mean time, keep using PowerShell every day. And if you haven't, checkout the other scripting challenges at https:\/\/ironscripter.us and try your hand at solving them. There's no time limit or expiration date and you might be surprised what you learn.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I thought I&#8217;d share my PowerShell solution to a recent Iron Scripter challenge. The challenge was to create PowerShell code that would create nonsense documents, with a goal of creating 10 sample files filled with gibberish. Yes, other than maybe wanting some test files to work with, on its face the challenge appears pointless.&nbsp;&#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 on the blog: Friday Fun - A #PowerShell Nonsense Challenge","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":[4,8],"tags":[224,618,221,534,540],"class_list":["post-7638","post","type-post","status-publish","format-standard","hentry","category-powershell","category-scripting","tag-function","tag-iron-scripter","tag-module","tag-powershell","tag-scripting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Friday Fun - A PowerShell Nonsense Challenge &#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\/7638\/friday-fun-a-powershell-nonsense-challenge\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Friday Fun - A PowerShell Nonsense Challenge &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"Today I thought I&#039;d share my PowerShell solution to a recent Iron Scripter challenge. The challenge was to create PowerShell code that would create nonsense documents, with a goal of creating 10 sample files filled with gibberish. Yes, other than maybe wanting some test files to work with, on its face the challenge appears pointless.&nbsp;...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/7638\/friday-fun-a-powershell-nonsense-challenge\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-07T15:51:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-09-30T20:44:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/08\/nnp.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\\\/7638\\\/friday-fun-a-powershell-nonsense-challenge\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7638\\\/friday-fun-a-powershell-nonsense-challenge\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Friday Fun &#8211; A PowerShell Nonsense Challenge\",\"datePublished\":\"2020-08-07T15:51:45+00:00\",\"dateModified\":\"2020-09-30T20:44:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7638\\\/friday-fun-a-powershell-nonsense-challenge\\\/\"},\"wordCount\":686,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7638\\\/friday-fun-a-powershell-nonsense-challenge\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/nnp.png\",\"keywords\":[\"Function\",\"Iron Scripter\",\"module\",\"PowerShell\",\"Scripting\"],\"articleSection\":[\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7638\\\/friday-fun-a-powershell-nonsense-challenge\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7638\\\/friday-fun-a-powershell-nonsense-challenge\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7638\\\/friday-fun-a-powershell-nonsense-challenge\\\/\",\"name\":\"Friday Fun - A PowerShell Nonsense Challenge &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7638\\\/friday-fun-a-powershell-nonsense-challenge\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7638\\\/friday-fun-a-powershell-nonsense-challenge\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/nnp.png\",\"datePublished\":\"2020-08-07T15:51:45+00:00\",\"dateModified\":\"2020-09-30T20:44:25+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7638\\\/friday-fun-a-powershell-nonsense-challenge\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7638\\\/friday-fun-a-powershell-nonsense-challenge\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7638\\\/friday-fun-a-powershell-nonsense-challenge\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/nnp.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/nnp.png\",\"width\":1314,\"height\":600},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7638\\\/friday-fun-a-powershell-nonsense-challenge\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Friday Fun &#8211; A PowerShell Nonsense Challenge\"}]},{\"@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 - A PowerShell Nonsense Challenge &#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\/7638\/friday-fun-a-powershell-nonsense-challenge\/","og_locale":"en_US","og_type":"article","og_title":"Friday Fun - A PowerShell Nonsense Challenge &#8226; The Lonely Administrator","og_description":"Today I thought I'd share my PowerShell solution to a recent Iron Scripter challenge. The challenge was to create PowerShell code that would create nonsense documents, with a goal of creating 10 sample files filled with gibberish. Yes, other than maybe wanting some test files to work with, on its face the challenge appears pointless.&nbsp;...","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7638\/friday-fun-a-powershell-nonsense-challenge\/","og_site_name":"The Lonely Administrator","article_published_time":"2020-08-07T15:51:45+00:00","article_modified_time":"2020-09-30T20:44:25+00:00","og_image":[{"url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/08\/nnp.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\/7638\/friday-fun-a-powershell-nonsense-challenge\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7638\/friday-fun-a-powershell-nonsense-challenge\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Friday Fun &#8211; A PowerShell Nonsense Challenge","datePublished":"2020-08-07T15:51:45+00:00","dateModified":"2020-09-30T20:44:25+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7638\/friday-fun-a-powershell-nonsense-challenge\/"},"wordCount":686,"commentCount":1,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7638\/friday-fun-a-powershell-nonsense-challenge\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/08\/nnp.png","keywords":["Function","Iron Scripter","module","PowerShell","Scripting"],"articleSection":["PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/7638\/friday-fun-a-powershell-nonsense-challenge\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7638\/friday-fun-a-powershell-nonsense-challenge\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7638\/friday-fun-a-powershell-nonsense-challenge\/","name":"Friday Fun - A PowerShell Nonsense Challenge &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7638\/friday-fun-a-powershell-nonsense-challenge\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7638\/friday-fun-a-powershell-nonsense-challenge\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/08\/nnp.png","datePublished":"2020-08-07T15:51:45+00:00","dateModified":"2020-09-30T20:44:25+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7638\/friday-fun-a-powershell-nonsense-challenge\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/7638\/friday-fun-a-powershell-nonsense-challenge\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7638\/friday-fun-a-powershell-nonsense-challenge\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/08\/nnp.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/08\/nnp.png","width":1314,"height":600},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7638\/friday-fun-a-powershell-nonsense-challenge\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"Friday Fun &#8211; A PowerShell Nonsense Challenge"}]},{"@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":8107,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8107\/scripting-challenge-meetup\/","url_meta":{"origin":7638,"position":0},"title":"Scripting Challenge Meetup","author":"Jeffery Hicks","date":"February 1, 2021","format":false,"excerpt":"As you probably know, I am the PowerShell problem master behind the challenges from the Iron Scripter site. Solving a PowerShell scripting challenge is a great way to test your skills and expand your knowledge. The final result is merely a means to an end. How you get there and\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/02\/rubik.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":9018,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9018\/an-iron-scripter-warm-up-solution\/","url_meta":{"origin":7638,"position":1},"title":"An Iron Scripter Warm-Up Solution","author":"Jeffery Hicks","date":"May 6, 2022","format":false,"excerpt":"We just wrapped up the 2022 edition of the PowerShell+DevOps Global Summit. It was terrific to be with passionate PowerShell professionals again. The culmination of the event is the Iron Scripter Challenge. You can learn more about this year's event and winner here. But there is more to the Iron\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":7559,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7559\/an-expanded-powershell-scripting-inventory-tool\/","url_meta":{"origin":7638,"position":2},"title":"An Expanded PowerShell Scripting Inventory Tool","author":"Jeffery Hicks","date":"June 19, 2020","format":false,"excerpt":"The other day I shared my code that I worked up to solve an Iron Scripter PowerShell challenge. One of the shortcomings was that I didn't address a challenge to include a property that would indicate what file was using a given command. I also felt I could do better\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/06\/get-psscriptinventory.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/06\/get-psscriptinventory.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/06\/get-psscriptinventory.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/06\/get-psscriptinventory.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/06\/get-psscriptinventory.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/06\/get-psscriptinventory.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":7489,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7489\/powershell-word-play\/","url_meta":{"origin":7638,"position":3},"title":"PowerShell Word Play","author":"Jeffery Hicks","date":"May 19, 2020","format":false,"excerpt":"A few weeks ago an Iron Scripter PowerShell challenge was issued that involved playing with words and characters. Remember, the Iron Scripter challenges aren't intended to create meaningful, production worthy code. They are designed to help you learn PowerShell fundamentals and scripting techniques. This particular challenge was aimed at beginner\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/doublechar.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/doublechar.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/doublechar.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/doublechar.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/doublechar.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/doublechar.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":8236,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8236\/solving-another-powershell-math-challenge\/","url_meta":{"origin":7638,"position":4},"title":"Solving Another PowerShell Math Challenge","author":"Jeffery Hicks","date":"March 22, 2021","format":false,"excerpt":"Last month, the Iron Scripter Chairman posted a \"fun\" PowerShell scripting challenge. Actually, a few math-related challenges . As with all these challenges, the techniques and concepts you use to solve the challenge are more important than the result itself. Here's how I approached the problems. Problem #1 The first\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/03\/get-possiblesum.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/03\/get-possiblesum.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/03\/get-possiblesum.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":7680,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7680\/friday-fun-back-to-school-with-powershell\/","url_meta":{"origin":7638,"position":5},"title":"Friday Fun: Back to School with PowerShell","author":"Jeffery Hicks","date":"September 11, 2020","format":false,"excerpt":"For today's fun with PowerShell, I thought I'd share my solutions for a recent Iron Scripter challenge. If you aren't familiar with these challenges, and you should be, they are designed to test your PowerShell skills and hopefully help you learn something new. There are challenges for all skill levels\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\/2020\/09\/get-cylindervolume-format.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-cylindervolume-format.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-cylindervolume-format.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-cylindervolume-format.png?resize=700%2C400&ssl=1 2x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/7638","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=7638"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/7638\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=7638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=7638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=7638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}