{"id":8821,"date":"2022-01-28T17:00:48","date_gmt":"2022-01-28T22:00:48","guid":{"rendered":"https:\/\/jdhitsolutions.com\/blog\/?p=8821"},"modified":"2022-01-28T17:00:52","modified_gmt":"2022-01-28T22:00:52","slug":"friday-fun-redacting-with-powershell","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8821\/friday-fun-redacting-with-powershell\/","title":{"rendered":"Friday Fun: Redacting with PowerShell"},"content":{"rendered":"\n<p>It has been a while since my last Friday Fun post. These are articles that use PowerShell in fun and off-beat ways. The goal is to demonstrate techniques and concepts not necessarily give you something ready for production. Today, I'm going to modify PowerShell output to hide, or redact, potentially sensitive information. I might want to do this if I am running a command and I'm going to save the results to a file or printer.<\/p>\n\n\n\n<p>For example, I can run a command like this in PowerShell.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/gcim-cs.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"146\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/gcim-cs-1024x146.png\" alt=\"get-ciminstance example\" class=\"wp-image-8822\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/gcim-cs-1024x146.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/gcim-cs-300x43.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/gcim-cs-768x110.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/gcim-cs-850x121.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/gcim-cs.png 1213w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>If I print this or send it to a file, I might not want the computername to be shown. Or maybe even my name. I want PowerShell to handle this for me. In short, I need to replace strings like 'Prospero' and 'Jeff Hicks' with some like XXX and 'Joe Doe'.<\/p>\n\n\n\n<p>PowerShell has a Replace operator. Or I can use regular expressions. Naturally, I wenbt with the latter. <\/p>\n\n\n\n<p>In order to accomplish this, I need to take the command output and convert it to an array of strings. My function, will take pipeline input. And because I wanted to include formatted output as well, I can't do any string replacements until all the pipelined input is complete. In other words, instead of having my string manipulation in the Process scriptblock, I'll move it to the End scriptblock. This means I need a mechanism to keep track of the incoming pipeline.<\/p>\n\n\n\n<p>In the Begin block, I'll define a generic list object.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\"> $in = [System.Collections.Generic.list[object]]::new()<\/code><\/pre>\n\n\n\n<p>In the Process block, I'll add each incoming object to the list.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\"> $in.Add($inputobject)<\/code><\/pre>\n\n\n\n<p>Then in the End block I can turn it into an array of strings.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\"> $out = ($in | Out-String).Split(\"`r`n\")<\/code><\/pre>\n\n\n\n<p>Because I wanted my code to be flexible, I'll use a hashtable of values.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$global:Redacted = @{$env:COMPUTERNAME = \"REDACTED\";\"Jeff Hicks\"=\"Roy Biv\" }<\/code><\/pre>\n\n\n\n<p>The key is the text I want to find and the value is the replacement text. I am ignoring case in my function. The function will find my computername in any casing and replace it with REDACTED. I went around in circles a few times finding the right regex approach. I wanted to take into account the target string being a standalone value as well as part of a longer string. You'll have to test to see if my approach meets your needs. One thing I will mention is that the length of the replacement string should no longer than the target string. Ideally, they should be identical.<\/p>\n\n\n\n<p>Because I might want to redact several strings, I'll enumerate the hashtable using the GetEnumerator() method. I'll build a regex pattern based on the key and then look for matches. If any are found, I'll replace text.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">foreach ($item in $redacted.getenumerator()) {\n    [regex]$r = \"(\\b)?$($item.key)(\\S+)?(\\b)?\"\n    $fixme = [System.Text.RegularExpressions.Regex]::Matches($out,$r,\"IgnoreCase\")\n    foreach ($fix in $fixme) {\n        Write-Verbose \"Replacing $($item.key) with $($item.value)\"\n        #replace the value and pad the length difference\n        $new = ($fix.value -replace $item.key, $item.value).PadRight($item.key.length)\n        #update the output string\n        $out =  $out -replace $fix.value, $new\n    } #foreach fix\n} #foreach redact item<\/code><\/pre>\n\n\n\n<p>My regex pattern is basically the hashtable key. It might be preceded by a word boundary (\\b). The '?' indicates the \\b pattern is optional. The key may optionally be follow by one or more non-whitespace characters (\\S+)?. This should handle situations where the key is part of a longer words like 'prospero.local'. The replacement should be 'REDACTED.local'.  Finally,there might be another word boundary (\\b)?.  After looping though the matches, the function writes the clean text to the pipeline.<\/p>\n\n\n\n<p>Here's how it looks in action.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/or-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"367\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/or-1-1024x367.png\" alt=\"redacted powershell sample\" class=\"wp-image-8823\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/or-1-1024x367.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/or-1-300x108.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/or-1-768x275.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/or-1-850x305.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/or-1.png 1160w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/or-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"583\" height=\"323\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/or-2.png\" alt=\"redacted powershell sample 2\" class=\"wp-image-8824\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/or-2.png 583w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/or-2-300x166.png 300w\" sizes=\"auto, (max-width: 583px) 100vw, 583px\" \/><\/a><\/figure>\n\n\n\n<p>Remember, this is only redacting the output. Here's the complete file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">#requires -version 5.1\n\n#the value should be less than or equal to the key\n$global:Redacted = @{$env:COMPUTERNAME = \"REDACTED\";\"Jeff Hicks\"=\"Roy Biv\" }\nFunction Out-Redacted {\n    [cmdletbinding()]\n    [outputtype(\"System.string\")]\n    [alias(\"or\")]\n    Param(\n        [Parameter(ValueFromPipeline)]\n        [object]$InputObject,\n        [Parameter(HelpMessage = \"Specify the redacted hashtable\")]\n        [ValidateScript({$_.keys.count -gt 0})]\n        [hashtable]$Redacted = $global:Redacted\n    )\n    Begin {\n        Write-Verbose \"[$((Get-Date).TimeofDay) BEGIN  ] Starting $($myinvocation.mycommand)\"\n        #initialize a list to hold the incoming objects\n        Write-Verbose \"[$((Get-Date).TimeofDay) BEGIN  ] Initializing a list\"\n        $in = [System.Collections.Generic.list[object]]::new()\n    } #begin\n\n    Process {\n        Write-Verbose \"[$((Get-Date).TimeofDay) PROCESS] $InputObject\"\n        #add each pipelined object to the list\n        $in.Add($inputobject)\n    } #process\n\n    End {\n        #take the data in $in and create an array of strings\n        $out = ($in | Out-String).Split(\"`r`n\")\n        Write-Verbose \"Processing $($out.count) lines\"\n        foreach ($item in $redacted.getenumerator()) {\n            [regex]$r = \"(\\b)?$($item.key)(\\S+)?(\\b)?\"\n            $fixme = [System.Text.RegularExpressions.Regex]::Matches($out,$r,\"IgnoreCase\")\n            foreach ($fix in $fixme) {\n                Write-Verbose \"Replacing $($item.key) with $($item.value)\"\n                #replace the value and pad the length difference\n                $new = ($fix.value -replace $item.key, $item.value).PadRight($item.key.length)\n                #update the output string\n                $out =  $out -replace $fix.value, $new\n            } #foreach fix\n        } #foreach redact item\n\n        #write the string result\n        $out\n\n        Write-Verbose \"[$((Get-Date).TimeofDay) END    ] Ending $($myinvocation.mycommand)\"\n\n    } #end\n\n} #close Out-Redacted<\/code><\/pre>\n\n\n\n<p>The Redacted parameter uses a default value of a globally defined hashtable.  When I dot-source this file, $Redacted is created in my session. I can modify this hashtable as much as needed without having to worry about the function.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/or-3.png\"><img loading=\"lazy\" decoding=\"async\" width=\"548\" height=\"230\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/or-3.png\" alt=\"modifying the redacted hashtable\" class=\"wp-image-8826\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/or-3.png 548w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/or-3-300x126.png 300w\" sizes=\"auto, (max-width: 548px) 100vw, 548px\" \/><\/a><\/figure>\n\n\n\n<p>Have Fun!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It has been a while since my last Friday Fun post. These are articles that use PowerShell in fun and off-beat ways. The goal is to demonstrate techniques and concepts not necessarily give you something ready for production. Today, I&#8217;m going to modify PowerShell output to hide, or redact, potentially sensitive information. I might want&#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: A Friday Fun post on using #PowerShell and regular expressions to sanitize command output.","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,199,534,268,540],"class_list":["post-8821","post","type-post","status-publish","format-standard","hentry","category-powershell","category-scripting","tag-function","tag-hashtable","tag-powershell","tag-regex","tag-scripting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Friday Fun: Redacting with PowerShell &#8226; The Lonely Administrator<\/title>\n<meta name=\"description\" content=\"Here&#039;s a fun PowerShell function to strip out sensitive information from command output. Offered as a learning opportunity.\" \/>\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\/8821\/friday-fun-redacting-with-powershell\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Friday Fun: Redacting with PowerShell &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"Here&#039;s a fun PowerShell function to strip out sensitive information from command output. Offered as a learning opportunity.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/8821\/friday-fun-redacting-with-powershell\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2022-01-28T22:00:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-01-28T22:00:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/gcim-cs-1024x146.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\\\/8821\\\/friday-fun-redacting-with-powershell\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8821\\\/friday-fun-redacting-with-powershell\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Friday Fun: Redacting with PowerShell\",\"datePublished\":\"2022-01-28T22:00:48+00:00\",\"dateModified\":\"2022-01-28T22:00:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8821\\\/friday-fun-redacting-with-powershell\\\/\"},\"wordCount\":589,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8821\\\/friday-fun-redacting-with-powershell\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/gcim-cs-1024x146.png\",\"keywords\":[\"Function\",\"hashtable\",\"PowerShell\",\"regex\",\"Scripting\"],\"articleSection\":[\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8821\\\/friday-fun-redacting-with-powershell\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8821\\\/friday-fun-redacting-with-powershell\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8821\\\/friday-fun-redacting-with-powershell\\\/\",\"name\":\"Friday Fun: Redacting with PowerShell &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8821\\\/friday-fun-redacting-with-powershell\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8821\\\/friday-fun-redacting-with-powershell\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/gcim-cs-1024x146.png\",\"datePublished\":\"2022-01-28T22:00:48+00:00\",\"dateModified\":\"2022-01-28T22:00:52+00:00\",\"description\":\"Here's a fun PowerShell function to strip out sensitive information from command output. Offered as a learning opportunity.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8821\\\/friday-fun-redacting-with-powershell\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8821\\\/friday-fun-redacting-with-powershell\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8821\\\/friday-fun-redacting-with-powershell\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/gcim-cs.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/gcim-cs.png\",\"width\":1213,\"height\":173},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8821\\\/friday-fun-redacting-with-powershell\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Friday Fun: Redacting with PowerShell\"}]},{\"@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: Redacting with PowerShell &#8226; The Lonely Administrator","description":"Here's a fun PowerShell function to strip out sensitive information from command output. Offered as a learning opportunity.","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\/8821\/friday-fun-redacting-with-powershell\/","og_locale":"en_US","og_type":"article","og_title":"Friday Fun: Redacting with PowerShell &#8226; The Lonely Administrator","og_description":"Here's a fun PowerShell function to strip out sensitive information from command output. Offered as a learning opportunity.","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8821\/friday-fun-redacting-with-powershell\/","og_site_name":"The Lonely Administrator","article_published_time":"2022-01-28T22:00:48+00:00","article_modified_time":"2022-01-28T22:00:52+00:00","og_image":[{"url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/gcim-cs-1024x146.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\/8821\/friday-fun-redacting-with-powershell\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8821\/friday-fun-redacting-with-powershell\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Friday Fun: Redacting with PowerShell","datePublished":"2022-01-28T22:00:48+00:00","dateModified":"2022-01-28T22:00:52+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8821\/friday-fun-redacting-with-powershell\/"},"wordCount":589,"commentCount":2,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8821\/friday-fun-redacting-with-powershell\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/gcim-cs-1024x146.png","keywords":["Function","hashtable","PowerShell","regex","Scripting"],"articleSection":["PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/8821\/friday-fun-redacting-with-powershell\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8821\/friday-fun-redacting-with-powershell\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8821\/friday-fun-redacting-with-powershell\/","name":"Friday Fun: Redacting with PowerShell &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8821\/friday-fun-redacting-with-powershell\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8821\/friday-fun-redacting-with-powershell\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/gcim-cs-1024x146.png","datePublished":"2022-01-28T22:00:48+00:00","dateModified":"2022-01-28T22:00:52+00:00","description":"Here's a fun PowerShell function to strip out sensitive information from command output. Offered as a learning opportunity.","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8821\/friday-fun-redacting-with-powershell\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/8821\/friday-fun-redacting-with-powershell\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8821\/friday-fun-redacting-with-powershell\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/gcim-cs.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/gcim-cs.png","width":1213,"height":173},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8821\/friday-fun-redacting-with-powershell\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"Friday Fun: Redacting with PowerShell"}]},{"@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":4895,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4895\/friday-fun-a-sysinternals-powershell-workflow\/","url_meta":{"origin":8821,"position":0},"title":"Friday Fun: A SysInternals PowerShell Workflow","author":"Jeffery Hicks","date":"February 12, 2016","format":false,"excerpt":"Over the years I've come up with a number of PowerShell tools to download the SysInternals tools to my desktop. And yes, I know that with PowerShell 5 and PowerShellGet I could download and install a SysInternals package. But that assumes the package is current.\u00a0 But that's not really the\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"image","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/02\/image_thumb-5.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/02\/image_thumb-5.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/02\/image_thumb-5.png?resize=525%2C300 1.5x"},"classes":[]},{"id":2503,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2503\/friday-fun-test-powershell-command-name\/","url_meta":{"origin":8821,"position":1},"title":"Friday Fun &#8211; Test PowerShell Command Name","author":"Jeffery Hicks","date":"October 12, 2012","format":false,"excerpt":"Earlier this week I exchanged a few tweets with @jonhtyler about coming up with a proper name for a PowerShell function he was developing. The suggested best practice is to use the Verb-Noun naming convention, using an accepted verb. You can see the verbs with the Get-Verb cmdlet. So I\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":6175,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6175\/more-fun-with-powershell-thrillers\/","url_meta":{"origin":8821,"position":2},"title":"More Fun with PowerShell Thrillers","author":"Jeffery Hicks","date":"November 20, 2018","format":false,"excerpt":"Last week I posted a Friday Fun article about using PowerShell to create a synopsis for a hypothetical thriller novel. Naturally I wasn't satisfied to leave it at that. Don't get me wrong, it was a good start. But I needed to take the next logical step. I had a\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\/2018\/11\/image_thumb-6.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/11\/image_thumb-6.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/11\/image_thumb-6.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/11\/image_thumb-6.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":1584,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1584\/friday-fun-add-scripting-signing-to-the-ise\/","url_meta":{"origin":8821,"position":3},"title":"Friday Fun Add Scripting Signing to the ISE","author":"Jeffery Hicks","date":"August 5, 2011","format":false,"excerpt":"Today's fun involves adding a menu item to the PowerShell ISE to make it easy to sign your scripts. I'm not going to go into the details about getting and installing a code signing certificate. I also assume you only have one installed. You can get this certificate by seasrching\u2026","rel":"","context":"In &quot;PowerShell ISE&quot;","block_context":{"text":"PowerShell ISE","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-ise\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4407,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4407\/friday-fun-a-powershell-macro\/","url_meta":{"origin":8821,"position":4},"title":"Friday Fun: A PowerShell Macro","author":"Jeffery Hicks","date":"May 15, 2015","format":false,"excerpt":"Today's Friday Fun is a little different in that it showcases two things I use almost every day: Microsoft Word and PowerShell. I am writing new articles and material almost daily and of course very often the content is PowerShell related. Usually I use the blog post template in Word\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":4169,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4169\/friday-fun-updated-ise-scripting-geek-module\/","url_meta":{"origin":8821,"position":5},"title":"Friday Fun: Updated ISE Scripting Geek Module","author":"Jeffery Hicks","date":"January 9, 2015","format":false,"excerpt":"A few years ago I published a module with a number of functions and enhancements for the PowerShell ISE. This ISEScriptingGeek module has remained popular over the last few years. But I wrote it for PowerShell v2. I have also come up with a number of new additions to the\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"geek","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2015\/01\/geek-150x150.png?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8821","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=8821"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8821\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=8821"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=8821"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=8821"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}