The problem is that you are using structures that are value types, as opposed to reference types. When accessing these members through the PowerShell '.' it returns a copy of this element of the structure to you, and the value assignment takes place on this copy and never gets into the object that you are trying to change.
Here is a small example demonstrating this:
> add-type @" namespace TestStructs { public struct Inner { public int i; }; public class Outer { public Inner i; } } "@ $s = new-object TestStructs.Outer
I created an Outer class that has an Inner structure as a member of i . If I try to assign a value, I get the behavior that you see where it stays at 0:
> $sii 0 > $sii = 6 > $sii 0
The way around this is to assign the whole structure. So, for this simple case, I can create a new structure, set the value, and then assign it to the object I want to change:
> $new_inner = new-object TestStructs.Inner > $new_inner.i 0 > $new_inner.i = 6 > $new_inner.i 6 > $si = $new_inner > $sii 6
I can use a few shortcuts to do this:
> $si = new-object TestStructs.Inner -prop @{ i = 7 } > $sii 7
This can be impractical if you have many meanings in your structure. This way you can also save it to a temporary value and reassign:
> $si = &{ $temp = $si; $temp.i = 10; $temp } H:\ > $sii 10
source share