DeepCopy.ps1

function DeepCopy {
    <#
    .SYNOPSIS
    This function ...
 
    .DESCRIPTION
    A bit more description
 
    .PARAMETER FromPipeline
    Shows how to process input from the pipeline, remaining parameters or by named parameter.
 
    .EXAMPLE
    DeepCopy 'abc'
 
    Description of the example.
 
    #>


    <# Enable -Confirm and -WhatIf. #>
    [CmdletBinding(SupportsShouldProcess = $true)]
    param(
        $data
    )

    begin {
    }

    process {
  $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()
  return $dataDeep
}

    end {
    }
}