We help IT Professionals succeed at work.
Get Started

Adding member to an array

TeekayShipping
on
53 Views
Last Modified: 2020-02-25
Hello,

Hoping someone can help as i cant find an answer to this. In PowerShell i'm trying to add a new proprty to an array i have imported:

To confirm it looks like this when its imported:

PS C:\Windows\system32> $ImportedForAppend

ConnectionName : AlexanderSpirit 10.13.126.0 (vessel) (Not being upgraded)
ID             : 9c503373-a37f-4f08-9cce-748721b0238e
Status         : DOWN   :-(  25-02:1224
IP             : 10.13.126.250
PingNumber     : 0
TimeStamp      : 25-02-2020:1224

ConnectionName : BahrainSpirit 10.12.24.0 (vessel)
ID             : 8d2ce4a0-bacc-477d-89ca-a02f8d1014fd
Status         : FAST 174ms 25-02:1224
IP             : 10.12.24.250
PingNumber     : 174
TimeStamp      : 25-02-2020:1224

ConnectionName : BarcelonaSpirit 10.12.18.0 (vessel)
ID             : c7a783b5-e650-4023-a58b-2739038b1b8b
Status         : FAST 737ms 25-02:1224
IP             : 10.12.18.250
PingNumber     : 737
TimeStamp      : 25-02-2020:1224


PS C:\Windows\system32> $ImportedForAppend.GetType();

IsPublic IsSerial Name                                     BaseType                                                                                                                                                                                              
-------- -------- ----                                     --------                                                                                                                                                                                              
True     True     Object[]                                 System.Array        
             


Now i'm trying to add a new property to the array with an updated time stamp and a new ping number, so it looks like this:

ConnectionName : AlexanderSpirit 10.13.126.0 (vessel) (Not being upgraded)
ID             : 9c503373-a37f-4f08-9cce-748721b0238e
Status         : DOWN   :-(  25-02:1224
IP             : 10.13.126.250
PingNumber     : 0
TimeStamp      : 25-02-2020:1224
25-02-2020:1250:    677

ConnectionName : BahrainSpirit 10.12.24.0 (vessel)
ID             : 8d2ce4a0-bacc-477d-89ca-a02f8d1014fd
Status         : FAST 174ms 25-02:1224
IP             : 10.12.24.250
PingNumber     : 174
TimeStamp      : 25-02-2020:1224
25-02-2020:1250:   1344

ConnectionName : BarcelonaSpirit 10.12.18.0 (vessel)
ID             : c7a783b5-e650-4023-a58b-2739038b1b8b
Status         : FAST 737ms 25-02:1224
IP             : 10.12.18.250
PingNumber     : 737
TimeStamp      : 25-02-2020:1224
25-02-2020:1250:     566


Question is how to target a specific "ConnectionName" and add a new property with the name/value so the layout stays the same?

I know i can use the below to add a new member but its adding a property to each group and i want to only target certain ones:

$ImportedForAppend | Add-Member -MemberType NoteProperty -Name $Vessel.TimeStamp -Value $CurrentStatusList.PingNumber


ConnectionName  : AlexanderSpirit 10.13.126.0 (vessel) (Not being upgraded)
ID              : 9c503373-a37f-4f08-9cce-748721b0238e
Status          : DOWN   :-(  25-02:1253
IP              : 10.13.126.250
PingNumber      : 0
TimeStamp       : 25-02-2020:1253
Test            : 455

ConnectionName  : BahrainSpirit 10.12.24.0 (vessel)
ID              : 8d2ce4a0-bacc-477d-89ca-a02f8d1014fd
Status          : FAST 221ms 25-02:1253
IP              : 10.12.24.250
PingNumber      : 221
TimeStamp       : 25-02-2020:1253
Test            : 455

ConnectionName  : BarcelonaSpirit 10.12.18.0 (vessel)
ID              : c7a783b5-e650-4023-a58b-2739038b1b8b
Status          : FAST 674ms 25-02:1253
IP              : 10.12.18.250
PingNumber      : 674
TimeStamp       : 25-02-2020:1253
Test            : 455

                                                                                                                                                                   
How to add only one extra property as below to say the "ConnectionName" "BarcelonaSpirit 10.12.18.0 (vessel)"

ConnectionName  : AlexanderSpirit 10.13.126.0 (vessel) (Not being upgraded)
ID              : 9c503373-a37f-4f08-9cce-748721b0238e
Status          : DOWN   :-(  25-02:1253
IP              : 10.13.126.250
PingNumber      : 0
TimeStamp       : 25-02-2020:1253

ConnectionName  : BahrainSpirit 10.12.24.0 (vessel)
ID              : 8d2ce4a0-bacc-477d-89ca-a02f8d1014fd
Status          : FAST 221ms 25-02:1253
IP              : 10.12.24.250
PingNumber      : 221
TimeStamp       : 25-02-2020:1253
Test            : 455

ConnectionName  : BarcelonaSpirit 10.12.18.0 (vessel)
ID              : c7a783b5-e650-4023-a58b-2739038b1b8b
Status          : FAST 674ms 25-02:1253
IP              : 10.12.18.250
PingNumber      : 674
TimeStamp       : 25-02-2020:1253
Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018
Commented:
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE