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
mklement0
  • 382,024
  • 64
  • 607
  • 775
hdsouza
  • 354
  • 4
  • 17
  • 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 }}` – Abraham Zinala Jan 24 '23 at 01:15

1 Answers1

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.

mklement0
  • 382,024
  • 64
  • 607
  • 775
  • 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 Jan 23 '23 at 23:51
  • @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. – mklement0 Jan 23 '23 at 23:57
  • 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 Jan 23 '23 at 23:59
  • 1
    @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. – mklement0 Jan 24 '23 at 00:01
  • 1
    @hdsouza, if your question concerns arrays, it is a duplicate with [Is there a PowerShell equivalent of paste (i.e., horizontal file concatenation)?](https://stackoverflow.com/q/68070226/1701026) and the cascaded other duplicates – iRon Jan 24 '23 at 09:05