{"id":7576,"date":"2020-07-07T14:33:07","date_gmt":"2020-07-07T18:33:07","guid":{"rendered":"https:\/\/jdhitsolutions.com\/blog\/?p=7576"},"modified":"2020-09-30T17:14:20","modified_gmt":"2020-09-30T21:14:20","slug":"answering-the-powershell-word-to-phone-challenge","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7576\/answering-the-powershell-word-to-phone-challenge\/","title":{"rendered":"Answering the PowerShell Word to Phone Challenge"},"content":{"rendered":"\n<p>A few weeks ago, the Iron Scripter challenge was to <a href=\"https:\/\/ironscripter.us\/text-me-a-powershell-dialer-challenge\/\" target=\"_blank\" rel=\"noopener noreferrer\">write code to convert a short string into its numeric values<\/a>using the alphabet as it is laid out on a telephone.&nbsp; A number of solutions have already been shared in the comments on the original post. There are certainly a number of ways to meet the challenge. Here's what I worked out.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Convert Text to Number<\/h2>\n\n\n\n<p>I started with a simple hashtable.<\/p>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">$phone = @{\n    2 = 'abc'\n    3 = 'def'\n    4 = 'ghi'\n    5 = 'jkl'\n    6 = 'mno'\n    7 = 'pqrs'\n    8 = 'tuv'\n    9 = 'wxyz'\n}<\/code><\/pre>\n\n\n\n<p>The keys, coincidentally named, correspond to the telephone keys on my phone. To convert 'help' means finding the value and its key.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1043\" height=\"236\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone1.jpg\" alt=\"phone1\" class=\"wp-image-7583\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone1.jpg 1043w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone1-300x68.jpg 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone1-1024x232.jpg 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone1-768x174.jpg 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone1-850x192.jpg 850w\" sizes=\"auto, (max-width: 1043px) 100vw, 1043px\" \/><\/figure>\n\n\n\n<p>The Name property shows me the key.&nbsp; I can repeat this process for the other letters, join the keys and get my result: 4357. Here's the function I'm using to make this easier and meet some of the challenge's other requirements.<\/p>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">Function Convert-TextToNumber {\n[cmdletbinding()]\n[Outputtype(\"int32\")]\n\r\n    Param(\r\n        [Parameter(Position = 0, Mandatory, ValueFromPipeline)]\r\n        [ValidatePattern(\"^[A-Za-z]{1,5}$\")]\r\n        [string]$Plaintext,\r\n        [Parameter(HelpMessage = \"A custom dictionary file which is updated everytime a word is converted\")]   \r\n        [string]$Dictionary = \"mywords.txt\"\r\n    )\r\n\r\n    Begin {\r\n        Write-Verbose \"[BEGIN  ] Starting: $($MyInvocation.Mycommand)\"\r\n\r\n        #define a simple hashtable\r\n        $phone = @{\r\n            2 = 'abc'\r\n            3 = 'def'\r\n            4 = 'ghi'\r\n            5 = 'jkl'\r\n            6 = 'mno'\r\n            7 = 'pqrs'\r\n            8 = 'tuv'\r\n            9 = 'wxyz'\r\n        }\r\n\r\n        #initialize a dictionary list\r\n        $dict = [System.Collections.Generic.List[string]]::new()\r\n        if (Test-Path -path $Dictionary) {\r\n            Write-Verbose \"[BEGIN  ] Loading user dictionary from $Dictionary\"            \r\n            (Get-Content -path $Dictionary).foreach({$dict.add($_)})\r\n            $originalCount = $dict.Count\r\n            Write-Verbose \"[BEGIN  ] Loaded $originalCount items\"\r\n        }\r\n    } #begin\r\n    Process {\r\n        Write-Verbose \"[PROCESS] Converting: $Plaintext\"\r\n        #add plaintext to dictionary if missing\r\n        if ($dict -notcontains $Plaintext) {\r\n            Write-Verbose \"[PROCESS] Adding to user dictionary\"\r\n            $dict.Add($plaintext)\r\n        }\r\n\r\n        #this is a technically a one-line expression\r\n        #get the matching key for each value and join together\r\n        ($plaintext.ToCharArray()).ForEach({\r\n         $val = $_ \r\n         ($phone.GetEnumerator().Where({$_.value -match $val}).name)}) -join \"\"\r\n    } #process\r\n\r\n    End {\r\n        #commit dictionary to file if new words were added\r\n        if ($dict.count -gt $originalCount) {\r\n            Write-Verbose \"[END    ] Ending: Saving updated dictionary $Dictionary\"\r\n            $dict | Out-File -FilePath $Dictionary -Encoding ascii -Force\r\n        }\r\n        Write-Verbose \"[END    ] Ending: $($MyInvocation.Mycommand)\"\r\n    } #end\r\n}\r\n    <\/code><\/pre>\n\n\n\n<p>The function accepts pipelined input of words that are no more than 5 characters long AND can only be alphabet characters, either upper or lower case. That's what I'm doing with the ValidatePattern regular expression.<\/p>\n\n\n\n<p>I am also planning ahead and keeping a text file of all converted words. If the plaintext doesn't exist in the file, it gets added. If the number of items in the dictionary list changes, I update the file in the End block. Note that I'm using a generic list object and not an array.<\/p>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">$dict = [System.Collections.Generic.List[string]]::new()<\/code><\/pre>\n\n\n\n<p>This type of object performs much better than an array. The difference is insignificant in this function, but I am moving more to this model instead of traditional arrays.<\/p>\n\n\n\n<p>The conversion is done in the Process block with this one-line expression.<\/p>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">($plaintext.ToCharArray()).ForEach({\n         $val = $_ \n         ($phone.GetEnumerator().Where({$_.value -match $val}).name)}) -join \"\"<\/code><\/pre>\n\n\n\n<p>Here's a taste of the function in action.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1059\" height=\"596\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone2.jpg\" alt=\"phone2\" class=\"wp-image-7584\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone2.jpg 1059w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone2-300x169.jpg 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone2-1024x576.jpg 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone2-768x432.jpg 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone2-850x478.jpg 850w\" sizes=\"auto, (max-width: 1059px) 100vw, 1059px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Convert Number to Text<\/h2>\n\n\n\n<p>Converting back is only a little more complex. I can use the same hashtable. This time, I need to get the value associated with each key. I can then build a regular expression pattern to search through my dictionary file. Let me showyou the Verbose output first to illustrate.<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7585\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone3.jpg\" alt=\"phone3\" width=\"1220\" height=\"254\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone3.jpg 1220w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone3-300x62.jpg 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone3-1024x213.jpg 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone3-768x160.jpg 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone3-850x177.jpg 850w\" sizes=\"auto, (max-width: 1220px) 100vw, 1220px\" \/><\/p>\n\n\n\n<p>This word file had everyting I had converted. Here's the same thing using a larger word file.<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7586\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone4.jpg\" alt=\"phone4\" width=\"1199\" height=\"308\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone4.jpg 1199w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone4-300x77.jpg 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone4-1024x263.jpg 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone4-768x197.jpg 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone4-850x218.jpg 850w\" sizes=\"auto, (max-width: 1199px) 100vw, 1199px\" \/><\/p>\n\n\n\n<p>Remember the phrase I converted earlier?<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7587\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone5.jpg\" alt=\"phone5\" width=\"1070\" height=\"534\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone5.jpg 1070w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone5-300x150.jpg 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone5-1024x511.jpg 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone5-768x383.jpg 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone5-850x424.jpg 850w\" sizes=\"auto, (max-width: 1070px) 100vw, 1070px\" \/><\/p>\n\n\n\n<p>It would take a little work but I could probably figure this out. Certainly, a higher quality word file helps. Which is why I started keeping track of what I converted.<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7588\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone6.jpg\" alt=\"phone6\" width=\"1166\" height=\"446\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone6.jpg 1166w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone6-300x115.jpg 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone6-1024x392.jpg 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone6-768x294.jpg 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone6-850x325.jpg 850w\" sizes=\"auto, (max-width: 1166px) 100vw, 1166px\" \/>Here's the complete function.<\/p>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">Function Convert-NumberToText {\n[cmdletbinding()]\n    Param(\r\n        [Parameter(Position = 0, Mandatory, ValueFromPipeline)]\r\n        [ValidateRange(2, 99999)]\r\n        [int]$NumericValue,\r\n        [Parameter(Mandatory,HelpMessage= \"Specify the path to the word dictionary file.\")]\r\n        [ValidateScript({Test-Path $_})]\r\n        [string]$Dictionary\r\n    )\r\n\r\n    Begin {\r\n        Write-Verbose \"[BEGIN  ] Starting: $($MyInvocation.Mycommand)\"\r\n\r\n        $phone = @{\r\n            2 = 'abc'\r\n            3 = 'def'\r\n            4 = 'ghi'\r\n            5 = 'jkl'\r\n            6 = 'mno'\r\n            7 = 'pqrs'\r\n            8 = 'tuv'\r\n            9 = 'wxyz'\r\n        }\r\n\r\n        Write-Verbose \"[BEGIN  ] Loading a word dictionary from $dictionary\"\r\n        $words = Get-Content -path $Dictionary\r\n\r\n        Write-Verbose \"[BEGIN  ] ...$($words.count) available words.\"\r\n\r\n        #define a regex to divide the numeric value\r\n        [regex]$rx = \"\\d{1}\"\r\n\r\n    } #begin\r\n    Process {\r\n        Write-Verbose \"[PROCESS] Converting: $NumericValue\"\r\n        $Values = ($rx.Matches($NumericValue).value).ForEach({ $val = $_ ; ($phone.GetEnumerator() | Where-Object {$_.name -match $val}).value})\r\n\r\n        Write-Verbose \"[PROCESS] Converting: Possible values: $($Values -join ',')\"\r\n        #build a regex pattern with a word boundary\r\n        $pattern = \"\\b\"\r\n        foreach ($value in $values ) {\r\n            $pattern += \"[$value]{1}\"\r\n        }\r\n        $patternb += \"\\b\"\r\n\r\n        Write-Verbose \"[PROCESS] Using pattern: $pattern\"\r\n        #output will be lower case\r\n        [System.Text.RegularExpressions.Regex]::Matches($words, $pattern, \"IgnoreCase\") |\r\n        Group-Object -Property Value |\r\n        Select-Object -ExpandProperty Name |\r\n        Sort-Object | \r\n        Foreach-Object {$_.tolower()}\r\n\r\n    } #process\r\n\r\n    End {\r\n        Write-Verbose \"[END    ] Ending: $($MyInvocation.Mycommand)\"\r\n    } #end\r\n}\r\n    <\/code><\/pre>\n\n\n\n<p>And if you want to try my larger word file, download it <a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/words.zip\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Learn More<\/h2>\n\n\n\n<p>There were a number of terrific learning opportunities in this challenge. If you find yourself wanting or needing to learn more, I encourage you to check out the PowerShell content on <a href=\"https:\/\/www.pluralsight.com\/search?q=powershell\" target=\"_blank\" rel=\"noopener noreferrer\">Pluralsight.com<\/a>. I even have a course on <a href=\"https:\/\/www.pluralsight.com\/courses\/powershell-regular-expressions\" target=\"_blank\" rel=\"noopener noreferrer\">PowerShell and Regular Expressions<\/a>. And to really take your scripting to the next level, grab a copy of T<a href=\"https:\/\/leanpub.com\/powershell-scripting-toolmaking\" target=\"_blank\" rel=\"noopener noreferrer\">he PowerShell Scripting and Toolmaking<\/a> book.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few weeks ago, the Iron Scripter challenge was to write code to convert a short string into its numeric valuesusing the alphabet as it is laid out on a telephone.&nbsp; A number of solutions have already been shared in the comments on the original post. There are certainly a number of ways to meet&#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: Answering the #PowerShell Word to Phone 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":[32,618,534,250],"class_list":["post-7576","post","type-post","status-publish","format-standard","hentry","category-powershell","category-scripting","tag-functions","tag-iron-scripter","tag-powershell","tag-regular-expressions"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Answering the PowerShell Word to Phone 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\/7576\/answering-the-powershell-word-to-phone-challenge\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Answering the PowerShell Word to Phone Challenge &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"A few weeks ago, the Iron Scripter challenge was to write code to convert a short string into its numeric valuesusing the alphabet as it is laid out on a telephone.&nbsp; A number of solutions have already been shared in the comments on the original post. There are certainly a number of ways to meet...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/7576\/answering-the-powershell-word-to-phone-challenge\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-07T18:33:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-09-30T21:14:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone1.jpg\" \/>\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=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7576\\\/answering-the-powershell-word-to-phone-challenge\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7576\\\/answering-the-powershell-word-to-phone-challenge\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Answering the PowerShell Word to Phone Challenge\",\"datePublished\":\"2020-07-07T18:33:07+00:00\",\"dateModified\":\"2020-09-30T21:14:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7576\\\/answering-the-powershell-word-to-phone-challenge\\\/\"},\"wordCount\":481,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7576\\\/answering-the-powershell-word-to-phone-challenge\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/phone1.jpg\",\"keywords\":[\"functions\",\"Iron Scripter\",\"PowerShell\",\"Regular Expressions\"],\"articleSection\":[\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7576\\\/answering-the-powershell-word-to-phone-challenge\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7576\\\/answering-the-powershell-word-to-phone-challenge\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7576\\\/answering-the-powershell-word-to-phone-challenge\\\/\",\"name\":\"Answering the PowerShell Word to Phone Challenge &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7576\\\/answering-the-powershell-word-to-phone-challenge\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7576\\\/answering-the-powershell-word-to-phone-challenge\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/phone1.jpg\",\"datePublished\":\"2020-07-07T18:33:07+00:00\",\"dateModified\":\"2020-09-30T21:14:20+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7576\\\/answering-the-powershell-word-to-phone-challenge\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7576\\\/answering-the-powershell-word-to-phone-challenge\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7576\\\/answering-the-powershell-word-to-phone-challenge\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/phone1.jpg\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/phone1.jpg\",\"width\":1043,\"height\":236},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7576\\\/answering-the-powershell-word-to-phone-challenge\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Answering the PowerShell Word to Phone 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":"Answering the PowerShell Word to Phone 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\/7576\/answering-the-powershell-word-to-phone-challenge\/","og_locale":"en_US","og_type":"article","og_title":"Answering the PowerShell Word to Phone Challenge &#8226; The Lonely Administrator","og_description":"A few weeks ago, the Iron Scripter challenge was to write code to convert a short string into its numeric valuesusing the alphabet as it is laid out on a telephone.&nbsp; A number of solutions have already been shared in the comments on the original post. There are certainly a number of ways to meet...","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7576\/answering-the-powershell-word-to-phone-challenge\/","og_site_name":"The Lonely Administrator","article_published_time":"2020-07-07T18:33:07+00:00","article_modified_time":"2020-09-30T21:14:20+00:00","og_image":[{"url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone1.jpg","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":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7576\/answering-the-powershell-word-to-phone-challenge\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7576\/answering-the-powershell-word-to-phone-challenge\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Answering the PowerShell Word to Phone Challenge","datePublished":"2020-07-07T18:33:07+00:00","dateModified":"2020-09-30T21:14:20+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7576\/answering-the-powershell-word-to-phone-challenge\/"},"wordCount":481,"commentCount":0,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7576\/answering-the-powershell-word-to-phone-challenge\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone1.jpg","keywords":["functions","Iron Scripter","PowerShell","Regular Expressions"],"articleSection":["PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/7576\/answering-the-powershell-word-to-phone-challenge\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7576\/answering-the-powershell-word-to-phone-challenge\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7576\/answering-the-powershell-word-to-phone-challenge\/","name":"Answering the PowerShell Word to Phone Challenge &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7576\/answering-the-powershell-word-to-phone-challenge\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7576\/answering-the-powershell-word-to-phone-challenge\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone1.jpg","datePublished":"2020-07-07T18:33:07+00:00","dateModified":"2020-09-30T21:14:20+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7576\/answering-the-powershell-word-to-phone-challenge\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/7576\/answering-the-powershell-word-to-phone-challenge\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7576\/answering-the-powershell-word-to-phone-challenge\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone1.jpg","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/07\/phone1.jpg","width":1043,"height":236},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7576\/answering-the-powershell-word-to-phone-challenge\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"Answering the PowerShell Word to Phone 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":9018,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9018\/an-iron-scripter-warm-up-solution\/","url_meta":{"origin":7576,"position":0},"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":8107,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8107\/scripting-challenge-meetup\/","url_meta":{"origin":7576,"position":1},"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":7489,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7489\/powershell-word-play\/","url_meta":{"origin":7576,"position":2},"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":7559,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7559\/an-expanded-powershell-scripting-inventory-tool\/","url_meta":{"origin":7576,"position":3},"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":7712,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7712\/answering-the-wsman-powershell-challenge\/","url_meta":{"origin":7576,"position":4},"title":"Answering the WSMan PowerShell Challenge","author":"Jeffery Hicks","date":"September 30, 2020","format":false,"excerpt":"Today, I thought I'd share my solution to a recent Iron Scripter challenge. I thought this was a fascinating task and one with a practical result.\u00a0 I'd encourage you to try your hand at the challenge and come back later to see how I tackled it. The challenge is not\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\/09\/get-psremotesessionuser-4.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-psremotesessionuser-4.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-psremotesessionuser-4.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-psremotesessionuser-4.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-psremotesessionuser-4.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-psremotesessionuser-4.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":7680,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7680\/friday-fun-back-to-school-with-powershell\/","url_meta":{"origin":7576,"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\/7576","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=7576"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/7576\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=7576"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=7576"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=7576"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}