Private/_CloneObject.ps1

1
2
3
4
5
6
7
8
9
function _CloneObject {
    # https://stackoverflow.com/questions/7468707/deep-copy-a-dictionary-hashtable-in-powershell
    param($DeepCopyObject)
    $memStream = new-object IO.MemoryStream
    $formatter = new-object Runtime.Serialization.Formatters.Binary.BinaryFormatter
    $formatter.Serialize($memStream,$DeepCopyObject)
    $memStream.Position=0
    $formatter.Deserialize($memStream)
}