{"id":3627,"date":"2014-01-24T10:43:20","date_gmt":"2014-01-24T15:43:20","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=3627"},"modified":"2014-01-24T10:43:20","modified_gmt":"2014-01-24T15:43:20","slug":"friday-fun-with-rest-regex-and-replacements","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3627\/friday-fun-with-rest-regex-and-replacements\/","title":{"rendered":"Friday Fun with REST, Regex and Replacements"},"content":{"rendered":"<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/computereye.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/computereye-150x150.png\" alt=\"computereye\" width=\"150\" height=\"150\" class=\"alignleft size-thumbnail wp-image-2165\" \/><\/a> I just love using the web cmdlets that were introduced in PowerShell 3.0. One of the cmdlets I use the most is Invoke-RESTMethod. This isn't because I'm dealing with sites that offer REST-ful services, but rather I like that the cmdlet does all the heavy lifting for me when I point it to an RSS feed. I thought I'd share some techniques for working with the results incorporating regular expressions and replacements.<\/p>\n<p>First, I need something to work with.<\/p>\n<pre class=\"lang:ps decode:true \" >$feed = Invoke-RestMethod -Uri http:\/\/powershell.org\/wp\/feed\/\r\n<\/pre>\n<p>Here's an example of what I get back:<\/p>\n<pre class=\"lang:batch decode:true \" >title       : PowerShell Tip from the Head Coach of the 2014 Winter Scripting Games: Design for Performance and Efficiency!\r\nlink        : http:\/\/powershell.org\/wp\/2014\/01\/23\/powershell-tip-from-the-head-coach-of-the-2014-winter-scripting-games-design-fo\r\n              r-performance-and-efficiency\/\r\ncomments    : {http:\/\/powershell.org\/wp\/2014\/01\/23\/powershell-tip-from-the-head-coach-of-the-2014-winter-scripting-games-design-f\r\n              or-performance-and-efficiency\/#comments, 0}\r\npubDate     : Thu, 23 Jan 2014 14:28:33 +0000\r\ncreator     : creator\r\ncategory    : {category, category, category, category...}\r\nguid        : guid\r\ndescription : description\r\nencoded     : encoded\r\ncommentRss  : http:\/\/powershell.org\/wp\/2014\/01\/23\/powershell-tip-from-the-head-coach-of-the-2014-winter-scripting-games-design-fo\r\n              r-performance-and-efficiency\/feed\/<\/pre>\n<p>The cmdlet, Invoke-RestMethod, has gone ahead and created XML elements. I didn't have to do anything. Next, I'd like to re-format the results and make it pretty. For example, the pubDate, while readable, won't sort as a true [datetime] because it is being represented as a string. And some properties, like Description, are buried a bit further.<\/p>\n<pre class=\"lang:ps decode:true \" >\r\nPS C:\\> $feed[1].description\r\n\r\n#cdata-section                                                                                                                   \r\n--------------                                                                                                                   \r\nThere are several concepts that come to mind when discussing the topic of designing your PowerShell commands for performance a...\r\n<\/pre>\n<p>I can start with something like this:<\/p>\n<pre class=\"lang:ps decode:true \" >\r\n$feed | Select Title,Link,\r\n@{Name=\"Description\";Expression={$_.description.InnerText}},\r\n@{Name=\"Published\";Expression={$_.PubDate -as [datetime]}}<\/pre>\n<p>I've grabbed the description text and treated the pubDate as a [datetime] object.<\/p>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/convertingxml1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/convertingxml1-1024x513.png\" alt=\"convertingxml\" width=\"474\" height=\"237\" class=\"aligncenter size-large wp-image-3630\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/convertingxml1-1024x513.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/convertingxml1-300x150.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/convertingxml1.png 1299w\" sizes=\"auto, (max-width: 474px) 100vw, 474px\" \/><\/a><\/p>\n<p>One of the first things I see looking at this in more detail is that the description is full of HTML code.<\/p>\n<pre class=\"lang:batch decode:true \" >\r\ntitle       : Scripting Games Winter 2014 \u2013 Team Discussion Tips\r\nlink        : http:\/\/powershell.org\/wp\/2014\/01\/06\/scripting-games-winter-2014-team-discussion-tips\/\r\nDescription : When you&#8217;re logged into the Games, you&#8217;ll notice that clicking on your team pulls up a &#8220;team \r\n              discussion&#8221; box. That&#8217;s a shared discussion area for you and your team. However, if you click on one \r\n              of the files you&#8217;ve uploaded, you&#8217;ll see the discussion turn into a &#8220;File Discussion.&#8221; We \r\n              retain a separate thread for<span class=\"continue-reading\">... <a \r\n              href=\"http:\/\/powershell.org\/wp\/2014\/01\/06\/scripting-games-winter-2014-team-discussion-tips\/\">Continue Reading \r\n              &#187;<\/a><\/span><div class='yarpp-related-rss'>\r\n              <h3>Related posts:<\/h3><ol>\r\n              <li><a href='http:\/\/powershell.org\/wp\/2013\/12\/19\/2014-winter-scripting-games-team-formation-tips\/' rel='bookmark' \r\n              title='2014 Winter Scripting Games: Team Formation Tips'>2014 Winter Scripting Games: Team Formation Tips<\/a><\/li>\r\n              <li><a href='http:\/\/powershell.org\/wp\/2014\/01\/02\/registration-and-team-formation-now-available-for-the-scripting-ga\r\n              mes-2014-winter\/' rel='bookmark' title='Registration and Team Formation NOW AVAILABLE for The Scripting Games \r\n              &#8211; 2014 Winter'>Registration and Team Formation NOW AVAILABLE for The Scripting Games &#8211; 2014 \r\n              Winter<\/a><\/li>\r\n              <li><a href='http:\/\/powershell.org\/wp\/2013\/10\/02\/seeking-coaches-and-judges-for-the-winter-scripting-games\/' \r\n              rel='bookmark' title='Seeking Coaches and Judges for the Winter Scripting Games'>Seeking Coaches and Judges for \r\n              the Winter Scripting Games<\/a><\/li>\r\n              <\/ol>\r\n              <\/div>\r\n              \r\nPublished   : 1\/6\/2014 10:42:52 AM\r\n<\/pre>\n<p>To make this easier to read I want to strip out HTML tags and convert things like \"&#8211;\" into something I can understand. Here's where regular expressions come into play.<\/p>\n<p>With a little online research I came up with a regular expression pattern to find HTML tags: <(.|\\n)+?> which I can use like this:<\/p>\n<pre class=\"lang:batch decode:true \" >\r\nPS C:\\> [regex]$rgx = \"<(.|\\n)+?>\"\r\nPS C:\\> $rgx.replace($feed[1].description.innertext,\"\")\r\nThere are several concepts that come to mind when discussing the topic of designing your PowerShell commands for performance and \r\nefficiency, but in my opinion one of the items at the top of the list is &#8220;Filtering Left&#8221; which is what I&#8217;ll be\r\n covering in this blog article. First, let&#8217;s start out by taking a... Continue Reading &#187;\r\nRelated posts:\r\nWinter Scripting Games 2014 Tip #1: Avoid the aliases\r\nWinter Scripting Games 2014 Tip #2: Use #Requires to let PowerShell do the work for you\r\nWinter Scripting Games 2014\r\n<\/pre>\n<p>The Replace() method took all matches and replaced them with \"\", effectively removing them from the text. Because, I have a number of items to potentially replace, I defined a hashtable.<\/p>\n<pre class=\"lang:ps decode:true \" >\r\n$decode=@{\r\n'<(.|\\n)+?>'= \"\"\r\n'&#8217;' = \"'\"\r\n'&#8220;' = '\"'\r\n'&#8221;' = '\"'\r\n'&#187;' = \"...\"\r\n'&#8211;' = \"--\"\r\n'\u00e2\u20ac\u201c' = \"@\"\r\n'&#160;' = \" \"\r\n }\r\n<\/pre>\n<p>Then in my Select-Object statement I can reformat the description text.<\/p>\n<pre class=\"lang:ps decode:true \">\r\n$feed | Select Title,\r\n@{Name=\"Description\";Expression={\r\n $text = $_.Description.InnerText\r\n #strip out html codes\r\n foreach ($key in $decode.keys) {\r\n  [regex]$rgx=$key\r\n  $text = $rgx.Replace($text,$decode.Item($key)).Trim()\r\n }\r\n #use the cleaned up text\r\n $text\r\n }},\r\n<\/pre>\n<p>PowerShell goes through the hashtable keys and replaces the text with the key value. The end result is that $text is now clean. Here is my final code<\/p>\n<pre class=\"lang:ps decode=true\">\r\n$feed = Invoke-RestMethod -Uri http:\/\/powershell.org\/wp\/feed\/\r\n\r\n#hash table of HTML codes\r\n#http:\/\/www.ascii.cl\/htmlcodes.htm\r\n$decode=@{\r\n'<(.|\\n)+?>'= \"\"\r\n'&#8217;' = \"'\"\r\n'&#8220;' = '\"'\r\n'&#8221;' = '\"'\r\n'&#187;' = \"...\"\r\n'&#8211;' = \"--\"\r\n'\u00e2\u20ac\u201c' = \"@\"\r\n'&#160;' = \" \"\r\n }\r\n\r\n<#\r\n Redefining some properties so that they are in proper case\r\n and look pretty\r\n#>\r\n$feed | Select @{Name=\"Title\";Expression={$_.title}},\r\n@{Name=\"Description\";Expression={\r\n $text = $_.Description.InnerText\r\n #strip out html codes\r\n foreach ($key in $decode.keys) {\r\n  [regex]$rgx=$key\r\n  $text = $rgx.Replace($text,$decode.Item($key)).Trim()\r\n }\r\n #use the cleaned up text\r\n $text\r\n }},\r\n@{Name=\"Published\";Expression={$_.PubDate -as [datetime]}},\r\n@{Name=\"Link\";Expression={$_.Link}},\r\n@{Name=\"Category\";Expression={$_.Category.innertext -join \",\"}}\r\n<\/pre>\n<p>The other addition I made was to get the text from the Category XML element and join the array of strings into a single line separated by commas. Here's the final result:<\/p>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/get-powershellorg.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/get-powershellorg-300x201.png\" alt=\"get-powershellorg\" width=\"300\" height=\"201\" class=\"aligncenter size-medium wp-image-3633\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/get-powershellorg-300x201.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/get-powershellorg.png 837w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>But wait, there's more! I have taken the output from Invoke-RestMethod and written new objects to the pipeline. One thing I could do is pipe the result to Out-GridView and use it as an object-picker.<\/p>\n<pre class=\"lang:ps decode=true\">\r\nc:\\scripts\\get-powershellorg.ps1 | \r\nout-gridview -Title \"Select one or more stories\" -PassThru |\r\nforeach { start $_.link }\r\n<\/pre>\n<p>I can send the results to Out-Gridview. From there I can select one or more items, click OK and have the item open in my web browser. Or how about this:<\/p>\n<pre class=\"lang:ps decode=true\">\r\nc:\\scripts\\get-powershellorg.ps1 |\r\nSelect Title,Description,Published,\r\n@{Name=\"Link\";Expression={ \"<a href=$($_.link) target='_blank'>$($_.link) <\/a>\"}},\r\nCategory |\r\nConvertTo-HTML -Title \"PowerShell.org\" | Out-string | \r\nforeach { $_.Replace(\"&lt;\",\"<\").Replace(\"&gt;\",\">\") } |\r\nout-file c:\\work\\psorg.htm -Encoding ascii\r\n<\/pre>\n<p>Here I have a couple of replacements going on. After running the script, I re-select the properties and customize the Link property to turn it into an HTML anchor link. I'm doing this so that when I convert to HTML I will get a table with a clickable link. Well, almost. You see when ConvertTo-HTML gets the text for the Link property it turns the < and > back into quoted HTML. Which means I need to turn that back in < and > before saving the results to a file. Notice I'm taking advantage of the pipeline in the ForEach script block.<\/p>\n<pre class=\"lang:ps decode=true\">\r\nforeach { $_.Replace(\"&lt;\",\"<\").Replace(\"&gt;\",\">\") } \r\n<\/pre>\n<p>The Replace() method writes the string object to the pipeline after replacing for < and then it replaces for >. The net result is two replacements with one command.<\/p>\n<p>I hope you had some fun with this and maybe learned a trick or two. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I just love using the web cmdlets that were introduced in PowerShell 3.0. One of the cmdlets I use the most is Invoke-RESTMethod. This isn&#8217;t because I&#8217;m dealing with sites that offer REST-ful services, but rather I like that the cmdlet does all the heavy lifting for me when I point it to an RSS&#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 Friday Fun with REST, Regex and Replacements in #PowerShell http:\/\/bit.ly\/M3Khxy","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":[568,429,534,250,540],"class_list":["post-3627","post","type-post","status-publish","format-standard","hentry","category-friday-fun","category-powershell","category-scripting","tag-friday-fun","tag-invoke-restmethod","tag-powershell","tag-regular-expressions","tag-scripting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Friday Fun with REST, Regex and Replacements &#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\/3627\/friday-fun-with-rest-regex-and-replacements\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Friday Fun with REST, Regex and Replacements &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"I just love using the web cmdlets that were introduced in PowerShell 3.0. One of the cmdlets I use the most is Invoke-RESTMethod. This isn&#039;t because I&#039;m dealing with sites that offer REST-ful services, but rather I like that the cmdlet does all the heavy lifting for me when I point it to an RSS...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/3627\/friday-fun-with-rest-regex-and-replacements\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2014-01-24T15:43:20+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/computereye-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=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3627\\\/friday-fun-with-rest-regex-and-replacements\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3627\\\/friday-fun-with-rest-regex-and-replacements\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Friday Fun with REST, Regex and Replacements\",\"datePublished\":\"2014-01-24T15:43:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3627\\\/friday-fun-with-rest-regex-and-replacements\\\/\"},\"wordCount\":565,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3627\\\/friday-fun-with-rest-regex-and-replacements\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2012\\\/04\\\/computereye-150x150.png\",\"keywords\":[\"Friday Fun\",\"Invoke-RestMethod\",\"PowerShell\",\"Regular Expressions\",\"Scripting\"],\"articleSection\":[\"Friday Fun\",\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3627\\\/friday-fun-with-rest-regex-and-replacements\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3627\\\/friday-fun-with-rest-regex-and-replacements\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3627\\\/friday-fun-with-rest-regex-and-replacements\\\/\",\"name\":\"Friday Fun with REST, Regex and Replacements &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3627\\\/friday-fun-with-rest-regex-and-replacements\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3627\\\/friday-fun-with-rest-regex-and-replacements\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2012\\\/04\\\/computereye-150x150.png\",\"datePublished\":\"2014-01-24T15:43:20+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3627\\\/friday-fun-with-rest-regex-and-replacements\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3627\\\/friday-fun-with-rest-regex-and-replacements\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3627\\\/friday-fun-with-rest-regex-and-replacements\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2012\\\/04\\\/computereye.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2012\\\/04\\\/computereye.png\",\"width\":\"896\",\"height\":\"1024\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3627\\\/friday-fun-with-rest-regex-and-replacements\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Friday Fun\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/friday-fun\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Friday Fun with REST, Regex and Replacements\"}]},{\"@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 with REST, Regex and Replacements &#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\/3627\/friday-fun-with-rest-regex-and-replacements\/","og_locale":"en_US","og_type":"article","og_title":"Friday Fun with REST, Regex and Replacements &#8226; The Lonely Administrator","og_description":"I just love using the web cmdlets that were introduced in PowerShell 3.0. One of the cmdlets I use the most is Invoke-RESTMethod. This isn't because I'm dealing with sites that offer REST-ful services, but rather I like that the cmdlet does all the heavy lifting for me when I point it to an RSS...","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3627\/friday-fun-with-rest-regex-and-replacements\/","og_site_name":"The Lonely Administrator","article_published_time":"2014-01-24T15:43:20+00:00","og_image":[{"url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/computereye-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":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3627\/friday-fun-with-rest-regex-and-replacements\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3627\/friday-fun-with-rest-regex-and-replacements\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Friday Fun with REST, Regex and Replacements","datePublished":"2014-01-24T15:43:20+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3627\/friday-fun-with-rest-regex-and-replacements\/"},"wordCount":565,"commentCount":1,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3627\/friday-fun-with-rest-regex-and-replacements\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/computereye-150x150.png","keywords":["Friday Fun","Invoke-RestMethod","PowerShell","Regular Expressions","Scripting"],"articleSection":["Friday Fun","PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/3627\/friday-fun-with-rest-regex-and-replacements\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3627\/friday-fun-with-rest-regex-and-replacements\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3627\/friday-fun-with-rest-regex-and-replacements\/","name":"Friday Fun with REST, Regex and Replacements &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3627\/friday-fun-with-rest-regex-and-replacements\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3627\/friday-fun-with-rest-regex-and-replacements\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/computereye-150x150.png","datePublished":"2014-01-24T15:43:20+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3627\/friday-fun-with-rest-regex-and-replacements\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/3627\/friday-fun-with-rest-regex-and-replacements\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3627\/friday-fun-with-rest-regex-and-replacements\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/computereye.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/computereye.png","width":"896","height":"1024"},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3627\/friday-fun-with-rest-regex-and-replacements\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Friday Fun","item":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},{"@type":"ListItem","position":2,"name":"Friday Fun with REST, Regex and Replacements"}]},{"@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":3140,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/3140\/friday-fun-quote-of-the-day-revised\/","url_meta":{"origin":3627,"position":0},"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":4222,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4222\/baby-its-cold-outside\/","url_meta":{"origin":3627,"position":1},"title":"Baby, It&#8217;s Cold Outside","author":"Jeffery Hicks","date":"February 16, 2015","format":false,"excerpt":"I don't know about your neck of the woods, but it is downright Arctic here. So I thought I'd polish up my PowerShell function to get weather data. #requires -version 3.0 Function Get-MyWeather { <# .Synopsis Get the weather for a US zip code .Description This command will query the\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"weather","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2015\/02\/weather-300x138.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":5132,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5132\/downloading-git-tips-with-powershell\/","url_meta":{"origin":3627,"position":2},"title":"Downloading Git Tips with PowerShell","author":"Jeffery Hicks","date":"June 27, 2016","format":false,"excerpt":"So I've been sharing a number of PowerShell tools I've created for working with Git, including a few for getting tips from the Git Tips project on GitHub. My initial work was based on the fact that I had a local clone of that repository and wanted to search the\u2026","rel":"","context":"In &quot;Git&quot;","block_context":{"text":"Git","link":"https:\/\/jdhitsolutions.com\/blog\/category\/git\/"},"img":{"alt_text":"getting all online git tips with PowerShell","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image_thumb-22.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image_thumb-22.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image_thumb-22.png?resize=525%2C300 1.5x"},"classes":[]},{"id":3881,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3881\/scraping-sysinternals\/","url_meta":{"origin":3627,"position":3},"title":"Scraping Sysinternals","author":"Jeffery Hicks","date":"June 16, 2014","format":false,"excerpt":"Recently I was conversing with someone about my PowerShell code that downloads tools from the live Sysinternals site. If you search the Internet, you'll find plenty of ways to achieve the same goal. But we were running into a problem where PowerShell was failing to get information from the site.\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"download-thumb","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/06\/download-thumb.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":4618,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4618\/friday-fun-holiday-shopping-with-powershell\/","url_meta":{"origin":3627,"position":4},"title":"Friday Fun: Holiday Shopping with PowerShell","author":"Jeffery Hicks","date":"November 27, 2015","format":false,"excerpt":"Once again, the holiday shopping season is upon us. But perhaps PowerShell can make it a little easier or at least a bit more fun. I'm sure many of you have shopped at NewEgg.com. Perhaps you plan to do so again this year for friends, family or even yourself. So\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":7278,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7278\/friday-fun-powershell-ascii-art\/","url_meta":{"origin":3627,"position":5},"title":"Friday Fun PowerShell ASCII Art","author":"Jeffery Hicks","date":"February 14, 2020","format":false,"excerpt":"Today's post is definitely on the fun side. In fact, I apologize in advance for the afternoon you are about to blow playing with this code. Those of you of a certain age will recall dial up modems and bulletin boards. Part of the experience was visual. Board operators often\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\/02\/image_thumb-17.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/image_thumb-17.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/image_thumb-17.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/image_thumb-17.png?resize=700%2C400&ssl=1 2x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3627","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=3627"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3627\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=3627"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=3627"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=3627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}