I am trying to use cmd for PowerShell Add-Member for all elements of an array, and then access the member that I added later, but it does not appear.
In the output of the code below, you can see that NoteProperty exists within the scope of the foreach statement, but it does not exist on the same object outside this scope.
How to get this script to display isPrime for both Get-Member calls?
$p = @(1) $p[0] | %{ add-member -inputobject $_ -membertype noteproperty -name isPrime -value $true; $_ | gm } $p[0] | gm
Output
TypeName: System.Int32 Name MemberType ---- ---------- CompareTo Method Equals Method GetHashCode Method GetType Method GetTypeCode Method ToString Method isPrime NoteProperty CompareTo Method Equals Method GetHashCode Method GetType Method GetTypeCode Method ToString Method
source share