Abhaya Ghatkar
Abhaya Ghatkar

Reputation: 351

Print array values one after another

I have two arrays with different values as follows

$DevID={101,102,103,104}
$ProdID={201,202,203,204}

And I want the output to be printed as the first DevID followed by ProdID,as shown below,

101
201

102
202

103
203

104
204

How can I get the above shown output in PowerShell?

Upvotes: 0

Views: 2840

Answers (1)

Martin Brandl
Martin Brandl

Reputation: 58921

Using the curly bracket you defined two scriptblocks. You instead want to use @(....):

$DevID=@(101,102,103,104)
$ProdID=@(201,202,203,204)

Now to get your desired output you could use a for-loop and access the lists by the current index:

for ($i = 0; $i -lt $DevID.Count; $i++)
{
    $DevID[$i]
    $ProdID[$i]
}

Output:

101
201
102
202
103
203
104
204

Upvotes: 1

Related Questions