Skip to content

Instantly share code, notes, and snippets.

@codaamok
Created November 26, 2022 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codaamok/edeea9258f6111c80082b21faa36f018 to your computer and use it in GitHub Desktop.
Save codaamok/edeea9258f6111c80082b21faa36f018 to your computer and use it in GitHub Desktop.
PowerShell max depth for serialising data objects into child scopes. Execute this and observe how data is progressively lost while PowerShell serialises the object into the scopes.
$xml = [xml]"<parent><child name='Adam'><grandchild name='Charlie'></grandchild></child></parent>"
$xml.parent
$xml.parent.child
$xml.parent.child.grandchild
Invoke-Command -ComputerName 'hostname' -ArgumentList $xml.parent -ScriptBlock {
param($xml)
$xml.child
$xml.grandchild
}
Invoke-Command -ComputerName 'hostname' -ArgumentList $xml.parent, (Get-Credential) -ScriptBlock {
param($xml, $cred)
Invoke-Command -VMName 'vmname' -Credential $cred -ArgumentList $xml -ScriptBlock {
param($xml)
$xml.child
$xml.grandparent
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment