Created
February 17, 2021 18:52
-
-
Save ByronScottJones/2bd4994bb9a6f23bfc44afd3a010b568 to your computer and use it in GitHub Desktop.
Powershell - Deep Clone of Hashtable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-DeepClone | |
{ | |
[cmdletbinding()] | |
param( | |
$InputObject | |
) | |
process | |
{ | |
if($InputObject -is [hashtable]) { | |
$clone = @{} | |
foreach($key in $InputObject.keys) | |
{ | |
$clone[$key] = Get-DeepClone $InputObject[$key] | |
} | |
return $clone | |
} else { | |
return $InputObject | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source: https://powershellexplained.com/2016-11-06-powershell-hashtable-everything-you-wanted-to-know-about/#deep-copies