0

Using PowerShell I need to combine two arrays $IP_Diff and $Line_Diff:

$IP_Diff = "10.1.101.17"
$Line_IP = (@{N="Initialize"}).N |  Select @{N = "Problem_IP";E={$IP_Diff -join ";"}}

$ServerName = "ExServer-01"
$Exist = "False"
$Line_Diff = (@{N="Initialize"}).N |  Select @{N = $ServerName;E={$Exist -join ";"}}

I need the Combined Array to be:

Problem_IP  ExServer-01
----------  -------------
10.1.101.17 False
1
  • Perhaps you meant something like this: @{$Line_IP = $Line_Diff}.GetEnumerator().Foreach{ [pscustomobject]@{ $_.Key.PSobject.Properties.Name = $_.Key.PSObject.Properties.Value; $_.Value.PSObject.Properties.Name = $_.Value.PSObject.Properties.Value }} Commented Jan 24, 2023 at 1:15

1 Answer 1

2

It looks like you're trying to construct a [pscustomobject] instance as follows:

$IP_Diff = "10.1.101.17"
$ServerName = "ExServer-01"
$Exist = "False"

[pscustomobject] @{
  Problem_IP = $IP_Diff
  $ServerName = $exist
}

The above produces the display output shown in your question.

Sign up to request clarification or add additional context in comments.

5 Comments

That will not work for me as I need to programmatically combine the two arrays together. As mentioned at the start -- combine $IP_Diff and $Line_Diff. This is part of a larger script where the array $Line_Diff will be created in a ForEach loop and I will need to append the resulting $Line_Diff of each foreach loop to the final array.
@hdsouza, despite your question's title, its body doesn't show arrays. Please update your question to provide meaningful sample input, along with matching expected output.
I just need to combine two arrays together. If I provide the full code, that will run into pages and no one is going to understand what is expected.
@hdsouza, meaningful (representative) sample input isn't the same as the full code. As it stands, it's unclear what you're asking, at least to me.
@hdsouza, if your question concerns arrays, it is a duplicate with Is there a PowerShell equivalent of paste (i.e., horizontal file concatenation)? and the cascaded other duplicates

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.