I\'m trying to create a complete copy of an existing array. Every time I try this it doesn\'t seem to work. The thing is that I\'m modifying the Object names inside the new
Since Powershell 3.0, same approach as Jaco's answer but using PSSerializer.
It uses a CliXML format compatible with Export-Clixml & Import-Clixml and personally I find it easier to read.
In theory, supports a nested hierarchy up to [int32]::MaxValue levels-deep
# Original data
$FruitsOriginal = Get-Fruits
# Serialize and Deserialize data using PSSerializer:
$_TempCliXMLString = [System.Management.Automation.PSSerializer]::Serialize($FruitsOriginal, [int32]::MaxValue)
$FruitsNew = [System.Management.Automation.PSSerializer]::Deserialize($_TempCliXMLString)
# Deep copy done.