I'm trying to pass a class object as an argument to Invoke-Command.
class A {
[string]$str_a
A($sa) {
$this.str_a = $sa
}
}
class B {
[string]$str_b
[A[]]$a_list
B($sb, $al) {
$this.str_b = $sb
$this.a_list = $al
}
}
$a_obj = [A]::new('a-object')
$b_obj = [B]::new('b-object', $a_obj)
Invoke-Command -Computername 'abc' -ScriptBlock {
param($b) $b
} -ArgumentList $b_obj
When the above is executed, I expect it to print $str_b and $a_list from the object $b.
Instead, only $str_b is printed. That makes sense as $a_list is "pointer equivalent" inside an object of type B.
Is there a way to flatten this object before sending it to the remote computer?
Or any other method that could solve this?