Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
PowerShell Deepcopy demo
# Get original data
$data = @{
First = 'Justin';
Last = 'Dearing';
Resume = @{
Experience = [HashTable[]]@(
@{
StartDate = [DateTime] (Get-Date '2002-03-23');
EndDate = [DateTime] (Get-Date '2007-05-15');
Company = 'ACME ISP';
Title = 'Support Technician';
};
@{
StartDate = [DateTime] (Get-Date '2007-05-16');
EndDate = [DateTime] (Get-Date)
Company = 'Innitech';
Title = 'Developer';
};
)
};
}
Write-Host
Write-Host $data.GetType().FullName
Write-Host "Shallow Copy"
$dataShallow = $data.Clone();
$dataShallow.Resume.Experience[1].Title = 'Senior Developer';
$data.Resume.Experience |%{ New-Object PSObject -Property $_ }
# Serialize and Deserialize data using BinaryFormatter
$ms = New-Object System.IO.MemoryStream
$bf = New-Object System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
$bf.Serialize($ms, $data)
$ms.Position = 0
$dataDeep = $bf.Deserialize($ms)
$ms.Close()
$dataDeep.Resume.Experience[1].Title = 'Junior Developer';
Write-Host "Deep Copy Original"
$data.Resume.Experience |%{ New-Object PSObject -Property $_ }
Write-Host "Deep Copy"
$dataDeep.Resume.Experience |%{ New-Object PSObject -Property $_ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.