1

Trying to concatenate two variables with an array inside them.

First variable contains:

 PS C:\WINDOWS\system32> $svcStatus

    Response Status
    -------- ------
         200 OK 

Second variable contains:

PS C:\WINDOWS\system32> $svcCall 

displayName     serviceTypeUrl                                                                                port servicePort
-----------     --------------                                                                                ---- -----------
AutnTestService http://demo1.ravn.co.uk/ravn-manage/api/v2/service_types/0310bf36-8fbd-4543-a79e-2b59f288d7e3 9000        9002


When they are joined:

PS C:\WINDOWS\system32>$mansvcApp = -join $svcStatus, $svcCall
$mansvcApp 
@{Response=200; Status=OK}

displayName     serviceTypeUrl                                                                                port servicePort
-----------     --------------                                                                                ---- -----------
AutnTestService http://demo1.ravn.co.uk/ravn-manage/api/v2/service_types/0310bf36-8fbd-4543-a79e-2b59f288d7e3 9000        9002

How can I get it to look like this:

displayName     serviceTypeUrl                                          port servicePort Response status
-----------     --------------                                          ---- ----------- -------- ------
AutnTestService http://demo1.blah.co.uk/blah/api/v2/service_types/0310b 9000    9002        200     OK
1
  • -join should be used to join elements of an array into a string like this: $MyArray -join "," Commented Dec 23, 2015 at 11:35

1 Answer 1

2

One way you could do it is like this:

$svcStatus | Add-Member -MemberType NoteProperty -Name displayname -Value $svcCall.displayname
$svcStatus | Add-Member -MemberType NoteProperty -Name serviceTypeUrl -Value $svcCall.serviceTypeUrl

If you have several columns to add and you don't want to a lot of typing then you could use a loop to do it like so:

$svcCall | Get-Member -MemberType NoteProperty | % {
    $n = $_.name
    $svcStatus | Add-Member -MemberType NoteProperty -Name $n -Value $svcCall."$n"
}
Sign up to request clarification or add additional context in comments.

2 Comments

Brilliant. Just what I was looking for. For better understanding why did you append $svcCall.displayname at the end.
-Name displayname -Value $svcCall.displayname indicates to me that you are appending the ending entries from svcCall to svcStatus.displayname. Shouldn't -Name be reflective of what the name of one of the tables within svcCall should be.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.