{"id":2711,"date":"2013-01-16T14:18:44","date_gmt":"2013-01-16T19:18:44","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=2711"},"modified":"2013-01-16T14:18:44","modified_gmt":"2013-01-16T19:18:44","slug":"rename-hashtable-key","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2711\/rename-hashtable-key\/","title":{"rendered":"Rename Hashtable Key"},"content":{"rendered":"<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/10\/talkbubble.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/10\/talkbubble-150x150.png\" alt=\"talkbubble\" width=\"150\" height=\"150\" class=\"alignleft size-thumbnail wp-image-1688\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/10\/talkbubble-150x150.png 150w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/10\/talkbubble-198x198.png 198w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/a>I use hashtables quite a bit. Often generating hashtables on the fly from other sources. But sometimes the hashtable keys that come from these external sources don't align with what I intend to do with the hashtable. For  example, one of the nifty things you can do with hashtables is splat them against a cmdlet or advanced function. Each hashtable key will bind to its corresponding parameter name. This makes it very easy to run a command and pass a bunch of parameters all at once. Here's an example of splatting in action.<\/p>\n<p><code><br \/>\nPS C:\\> $hash = @{Computername=\"Serenity\";Class=\"AntivirusProduct\";Namespace=\"root\\securitycenter2\"}<br \/>\nPS C:\\> get-wmiobject @haSH<\/p>\n<p>__GENUS                  : 2<br \/>\n__CLASS                  : AntiVirusProduct<br \/>\n__SUPERCLASS             :<br \/>\n__DYNASTY                : AntiVirusProduct<br \/>\n__RELPATH                : AntiVirusProduct.instanceGuid=\"{D68DDC3A-831F-4fae-9E44-DA132C1ACF46}\"<br \/>\n__PROPERTY_COUNT         : 6<br \/>\n__DERIVATION             : {}<br \/>\n__SERVER                 : SERENITY<br \/>\n__NAMESPACE              : ROOT\\securitycenter2<br \/>\n__PATH                   : \\\\SERENITY\\ROOT\\securitycenter2:AntiVirusProduct.instanceGuid=\"{D68DDC3A<br \/>\n                           -831F-4fae-9E44-DA132C1ACF46}\"<br \/>\ndisplayName              : Windows Defender<br \/>\ninstanceGuid             : {D68DDC3A-831F-4fae-9E44-DA132C1ACF46}<br \/>\npathToSignedProductExe   : %ProgramFiles%\\Windows Defender\\MSASCui.exe<br \/>\npathToSignedReportingExe : %ProgramFiles%\\Windows Defender\\MsMpeng.exe<br \/>\nproductState             : 397568<br \/>\ntimestamp                : Fri, 04 Jan 2013 17:09:42 GMT<br \/>\n<\/code><\/p>\n<p>This works because all of the hashtable keys line up with parameter names. If the names don't match they are ignore. So sometimes I need to rename the hashtable key. This isn't too difficult conceptually.<\/p>\n<p>1. Create a new entry with the new key name and the old value<br \/>\n2. Remove the existing key.<\/p>\n<p>But, I decided to turn this into an advanced function, probably with more bells and whistles than I really need. But maybe you will learn something new from my efforts.<\/p>\n<p><code lang=\"PowerShell\"><br \/>\nFunction Rename-HashTable {<br \/>\n#comment based help is here<\/p>\n<p>[cmdletbinding(SupportsShouldProcess=$True)]<\/p>\n<p>Param(<br \/>\n[parameter(position=0,Mandatory=$True,<br \/>\nHelpMessage=\"Enter the name of your hash table variable without the `$\")]<br \/>\n[ValidateNotNullorEmpty()]<br \/>\n[string]$Name,<br \/>\n[parameter(position=1,Mandatory=$True,<br \/>\nHelpMessage=\"Enter the existing key name you want to rename\")]<br \/>\n[ValidateNotNullorEmpty()]<br \/>\n[string]$Key,<br \/>\n[parameter(position=2,Mandatory=$True,<br \/>\nHelpMessage=\"Enter the NEW key name\")]<br \/>\n[ValidateNotNullorEmpty()]<br \/>\n[string]$NewKey,<br \/>\n[switch]$Passthru,<br \/>\n[ValidateSet(\"Global\",\"Local\",\"Script\",\"Private\",0,1,2,3)]<br \/>\n[ValidateNotNullOrEmpty()]<br \/>\n[string]$Scope=\"Global\"<br \/>\n)<\/p>\n<p>#validate Key and NewKey are not the same<br \/>\nif ($key -eq $NewKey) {<br \/>\n Write-Warning \"The values you specified for -Key and -NewKey appear to be the same. Names are NOT case-sensitive\"<br \/>\n Return<br \/>\n}<\/p>\n<p>Try {<br \/>\n    #validate variable is a hash table<br \/>\n    write-verbose (gv -Scope $scope | out-string)<br \/>\n    Write-Verbose \"Validating $name as a hashtable in $Scope scope.\"<br \/>\n    #get the variable<br \/>\n    $var = Get-Variable -Name $name -Scope $Scope -ErrorAction Stop<\/p>\n<p>    if ( $var.Value -is [hashtable]) {<br \/>\n        #create a temporary copy<br \/>\n        Write-Verbose \"Cloning a temporary hashtable\"<br \/>\n        <#\n            Use the clone method to create a separate copy.\n            If you just assign the value to $temphash, the\n            two hash tables are linked in memory so changes\n            to $tempHash are also applied to the original\n            object.\n        #><br \/>\n        $tempHash = $var.Value.Clone()<br \/>\n        #validate key exists<br \/>\n        Write-Verbose \"Validating key $key\"<br \/>\n        if ($tempHash.Contains($key)) {<br \/>\n            #create a key with the new name using the value from the old key<br \/>\n            Write-Verbose \"Adding new key $newKey to the temporary hashtable\"<br \/>\n            $tempHash.Add($NewKey,$tempHash.$Key)<br \/>\n            #remove the old key<br \/>\n            Write-Verbose \"Removing $key\"<br \/>\n            $tempHash.Remove($Key)<br \/>\n            #write the new value to the variable<br \/>\n            Write-Verbose \"Writing the new hashtable\"<br \/>\n            Write-Verbose ($tempHash | out-string)<br \/>\n            Set-Variable -Name $Name -Value $tempHash -Scope $Scope -Force -PassThru:$Passthru |<br \/>\n            Select-Object -ExpandProperty Value<br \/>\n        }<br \/>\n        else {<br \/>\n            Write-Warning \"Can't find a key called $Key in `$$Name\"<br \/>\n        }<br \/>\n    }<br \/>\n    else {<br \/>\n        Write-Warning \"The variable $name does not appear to be a hash table.\"<br \/>\n    }<br \/>\n} #Try<\/p>\n<p>Catch {<br \/>\n    Write-Warning \"Failed to find a variable with a name of $Name.\"<br \/>\n}<\/p>\n<p>Write-Verbose \"Rename complete\"<br \/>\n} #end Rename-Hashtable<br \/>\n<\/code><\/p>\n<p>The function assumes you have saved the hashtable to a variable. Pass the variable name as a parameter, without the $ character. The function uses Get-Variable to retrieve the variable. Remember that variables are scope specific so I need to specify the scope to search. I'm defaulting to the global scope. Otherwise, when the function runs, it is in its own scope which doesn't include the hashtable variable. Now, I could have simply attempted to read the variable, trusting PowerShell to read up the scope until it found it, but the best practice is to avoid referencing out of scope items.<\/p>\n<p>Once the variable is found, its value is the actual hashtable which I verify as a [hashtable] object.<\/p>\n<p><code lang=\"PowerShell\"><br \/>\nif ( $var.Value -is [hashtable]) {<br \/>\n<\/code><\/p>\n<p>From here I create a cloned copy of the original variable. <\/p>\n<p><code lang=\"PowerShell\"><br \/>\n$tempHash = $var.Value.Clone()<br \/>\n<\/code><\/p>\n<p>By the way, you'll notice my functions supports ShouldProcess. This means I can use -WhatIf and it will be passed to any cmdlets that also support it. At the end of my command I use Set-Variable which supports ShouldProcess so if I run my function with -WhatIf, Set-Variable will also use -Whatif. This is a long way of saying I can run the command in \"test\" mode without having to worry about changing the original hash table. This is also why I create a clone instead of simply setting the value of my temporary hash table to the original hash table. When you do that, the two variables are actually linked so any changes in one are made to other. Here's an example of what I'm talking about:<\/p>\n<p><code><br \/>\nPS C:\\> $a = @{A=1;B=2;C=3}<br \/>\nPS C:\\> $a<\/p>\n<p>Name                           Value<br \/>\n----                           -----<br \/>\nA                              1<br \/>\nB                              2<br \/>\nC                              3<\/p>\n<p>PS C:\\> $b=$a<br \/>\nPS C:\\> $b<\/p>\n<p>Name                           Value<br \/>\n----                           -----<br \/>\nA                              1<br \/>\nB                              2<br \/>\nC                              3<\/p>\n<p>PS C:\\> $b.Add(\"D\",4)<br \/>\nPS C:\\> $b<\/p>\n<p>Name                           Value<br \/>\n----                           -----<br \/>\nA                              1<br \/>\nB                              2<br \/>\nD                              4<br \/>\nC                              3<\/p>\n<p>PS C:\\> $a<\/p>\n<p>Name                           Value<br \/>\n----                           -----<br \/>\nA                              1<br \/>\nB                              2<br \/>\nD                              4<br \/>\nC                              3<br \/>\n<\/code><\/p>\n<p>Since I want my temp copy to be \"unattached\", I use the hashtable's Clone() method. From here, it is simply a matter of creating the new key with the old value, and removing the old key with a little error handling along the way.<\/p>\n<p><code lang=\"PowerShell\"><br \/>\nif ($tempHash.Contains($key)) {<br \/>\n    #create a key with the new name using the value from the old key<br \/>\n    Write-Verbose \"Adding new key $newKey to the temporary hashtable\"<br \/>\n    $tempHash.Add($NewKey,$tempHash.$Key)<br \/>\n    #remove the old key<br \/>\n    Write-Verbose \"Removing $key\"<br \/>\n    $tempHash.Remove($Key)<br \/>\n    #write the new value to the variable<br \/>\n    Write-Verbose \"Writing the new hashtable\"<br \/>\n    Write-Verbose ($tempHash | out-string)<br \/>\n    Set-Variable -Name $Name -Value $tempHash -Scope $Scope -Force -PassThru:$Passthru |<br \/>\n    Select-Object -ExpandProperty Value<br \/>\n}<br \/>\n<\/code><\/p>\n<p>At the end of the process I use Set-Variable to update my original hashtable variable. By default the cmdlet doesn't write anything to the pipeline but on the chance I might need the output, I use -Passthru and send the variable value, which is the revised hashtable, back to the pipeline. With this function I can now do something like this very easily.<\/p>\n<p><code><br \/>\nPS C:\\> $hash = @{name=\"Serenity\";Class=\"AntivirusProduct\";Namespace=\"root\\securitycenter2\"}<br \/>\nPS C:\\> $hash<\/p>\n<p>Name                           Value<br \/>\n----                           -----<br \/>\nname                           Serenity<br \/>\nClass                          AntivirusProduct<br \/>\nNamespace                      root\\securitycenter2<\/p>\n<p>PS C:\\> Rename-HashTable -Name hash -Key name -NewKey Computername<br \/>\nPS C:\\> $hash<\/p>\n<p>Name                           Value<br \/>\n----                           -----<br \/>\nClass                          AntivirusProduct<br \/>\nNamespace                      root\\securitycenter2<br \/>\nComputername                   Serenity<br \/>\n<\/code><\/p>\n<p>Now $hash has the right key names for splatting, or whatever else I have in mind. This function can come in handy with <a href=\"http:\/\/bit.ly\/mYDACc\" title=\"read my article about ConvertTo-Hashtable\" target=\"_blank\">ConvertTo-HashTable<\/a>.  Download <a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/01\/Rename-Hashtable.txt\" target=\"_blank\">Rename-Hashtable<\/a> and as always I hope you'll let me know what you think.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I use hashtables quite a bit. Often generating hashtables on the fly from other sources. But sometimes the hashtable keys that come from these external sources don&#8217;t align with what I intend to do with the hashtable. For example, one of the nifty things you can do with hashtables is splat them against a cmdlet&#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":"","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":[199,534,540],"class_list":["post-2711","post","type-post","status-publish","format-standard","hentry","category-powershell","category-scripting","tag-hashtable","tag-powershell","tag-scripting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Rename Hashtable Key &#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\/2711\/rename-hashtable-key\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Rename Hashtable Key &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"I use hashtables quite a bit. Often generating hashtables on the fly from other sources. But sometimes the hashtable keys that come from these external sources don&#039;t align with what I intend to do with the hashtable. For example, one of the nifty things you can do with hashtables is splat them against a cmdlet...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/2711\/rename-hashtable-key\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2013-01-16T19:18:44+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/10\/talkbubble-150x150.png\" \/>\n<meta name=\"author\" content=\"Jeffery Hicks\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:site\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeffery Hicks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2711\\\/rename-hashtable-key\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2711\\\/rename-hashtable-key\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Rename Hashtable Key\",\"datePublished\":\"2013-01-16T19:18:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2711\\\/rename-hashtable-key\\\/\"},\"wordCount\":592,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2711\\\/rename-hashtable-key\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2011\\\/10\\\/talkbubble-150x150.png\",\"keywords\":[\"hashtable\",\"PowerShell\",\"Scripting\"],\"articleSection\":[\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2711\\\/rename-hashtable-key\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2711\\\/rename-hashtable-key\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2711\\\/rename-hashtable-key\\\/\",\"name\":\"Rename Hashtable Key &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2711\\\/rename-hashtable-key\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2711\\\/rename-hashtable-key\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2011\\\/10\\\/talkbubble-150x150.png\",\"datePublished\":\"2013-01-16T19:18:44+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2711\\\/rename-hashtable-key\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2711\\\/rename-hashtable-key\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2711\\\/rename-hashtable-key\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2011\\\/10\\\/talkbubble.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2011\\\/10\\\/talkbubble.png\",\"width\":\"198\",\"height\":\"208\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2711\\\/rename-hashtable-key\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Rename Hashtable Key\"}]},{\"@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":"Rename Hashtable Key &#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\/2711\/rename-hashtable-key\/","og_locale":"en_US","og_type":"article","og_title":"Rename Hashtable Key &#8226; The Lonely Administrator","og_description":"I use hashtables quite a bit. Often generating hashtables on the fly from other sources. But sometimes the hashtable keys that come from these external sources don't align with what I intend to do with the hashtable. For example, one of the nifty things you can do with hashtables is splat them against a cmdlet...","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2711\/rename-hashtable-key\/","og_site_name":"The Lonely Administrator","article_published_time":"2013-01-16T19:18:44+00:00","og_image":[{"url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/10\/talkbubble-150x150.png","type":"","width":"","height":""}],"author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2711\/rename-hashtable-key\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2711\/rename-hashtable-key\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Rename Hashtable Key","datePublished":"2013-01-16T19:18:44+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2711\/rename-hashtable-key\/"},"wordCount":592,"commentCount":1,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2711\/rename-hashtable-key\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/10\/talkbubble-150x150.png","keywords":["hashtable","PowerShell","Scripting"],"articleSection":["PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/2711\/rename-hashtable-key\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2711\/rename-hashtable-key\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2711\/rename-hashtable-key\/","name":"Rename Hashtable Key &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2711\/rename-hashtable-key\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2711\/rename-hashtable-key\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/10\/talkbubble-150x150.png","datePublished":"2013-01-16T19:18:44+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2711\/rename-hashtable-key\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/2711\/rename-hashtable-key\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2711\/rename-hashtable-key\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/10\/talkbubble.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/10\/talkbubble.png","width":"198","height":"208"},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2711\/rename-hashtable-key\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"Rename Hashtable Key"}]},{"@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":2740,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2740\/join-powershell-hash-tables\/","url_meta":{"origin":2711,"position":0},"title":"Join PowerShell Hash Tables","author":"Jeffery Hicks","date":"January 23, 2013","format":false,"excerpt":"I received a lot of feedback and interest in my ConvertTo-Hashtable function. One question I received was \"Why?\" Well, one reason might be that you want to combine two objects into a single object. Joining them as two hashtables makes this an easier process. First off, combining two hashtables is\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"handshake","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/01\/handshake.gif?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":2733,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2733\/convert-powershell-object-to-hashtable-revised\/","url_meta":{"origin":2711,"position":1},"title":"Convert PowerShell Object to Hashtable Revised","author":"Jeffery Hicks","date":"January 22, 2013","format":false,"excerpt":"A while back I posted an advanced PowerShell function that would take an object and convert it to a hashtable. The premise was simple enough: look at the incoming object with Get-Member to discover the property names then create a hashtable with each property name as a hashtable key. I've\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"squarepattern","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/squarepattern-150x150.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":4800,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4800\/testing-powershell-hashtables\/","url_meta":{"origin":2711,"position":2},"title":"Testing PowerShell HashTables","author":"Jeffery Hicks","date":"January 14, 2016","format":false,"excerpt":"So I've been watching the PowerShell Toolmaking Fundamentals course on Pluralsight authored by Adam Bertram.\u00a0 You may be surprised that I watch other PowerShell related courses, but I always pick up something I didn't know about, find a new teaching technique or something else that makes me say, \"that was\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"image","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/01\/image_thumb-4.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/01\/image_thumb-4.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/01\/image_thumb-4.png?resize=525%2C300 1.5x"},"classes":[]},{"id":2752,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2752\/rename-hashtable-key-revised\/","url_meta":{"origin":2711,"position":3},"title":"Rename Hashtable Key Revised","author":"Jeffery Hicks","date":"January 24, 2013","format":false,"excerpt":"Last week I posted an advanced PowerShell function to rename a hashtable key. As usual, the more I worked with it the more I realized it was missing something - namely the ability the take a pipelined object. My original version assumed you had saved the hashtable to a variable.\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"rename-hashtable-paramsets","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/01\/rename-hashtable-paramsets-1024x319.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/01\/rename-hashtable-paramsets-1024x319.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/01\/rename-hashtable-paramsets-1024x319.png?resize=525%2C300 1.5x"},"classes":[]},{"id":3073,"url":"https:\/\/jdhitsolutions.com\/blog\/friday-fun\/3073\/friday-fun-view-objects-in-a-powershell-gridlist\/","url_meta":{"origin":2711,"position":4},"title":"Friday Fun: View Objects in a PowerShell GridList","author":"Jeffery Hicks","date":"May 24, 2013","format":false,"excerpt":"One of the things that makes PowerShell easy to learn is discoverability. Want to know more about a particular type of object? Pipe it to Get-Member. Or if you want to see values pipe it to Select-Object. get-ciminstance win32_computersystem | select * That's not too bad. Or you can pipe\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"Select-OutGridView","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/Select-OutGridView-300x72.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":2809,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2809\/powershell-morning-report-with-credentials\/","url_meta":{"origin":2711,"position":5},"title":"PowerShell Morning Report with Credentials","author":"Jeffery Hicks","date":"February 22, 2013","format":false,"excerpt":"I had an email about trying to use my Morning Report script to connect to machines that required alternate credentials. For example, you might have non-domain systems in a DMZ. Fair enough. Since most of the report script uses WMI, it wasn't too hard to add a Credential parameter and\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"morning report","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/02\/morningreport-revised-cred-1024x654.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/02\/morningreport-revised-cred-1024x654.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/02\/morningreport-revised-cred-1024x654.png?resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2711","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=2711"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2711\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=2711"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=2711"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=2711"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}