A simple question about foreach usage

[10.1.1.1]: PS C:\Users\admin\Documents> $ips = cat .\ip.txt

[10.1.1.1]: PS C:\Users\admin\Documents> $names = cat .\name.txt

[10.1.1.1]: PS C:\Users\admin\Documents> $ips,$names | foreach {$_,$_}

I hope the output will be like bellow, how ever, it’s not. Any one can help me ?

10.1.1.11  P-P01
10.1.1.12  P-P02
10.1.1.13  P-P03
10.1.1.14  P-P04
10.1.1.15  P-P05
10.1.1.16  P-P06
10.1.1.17  P-P07
10.1.1.18  P-P08
10.1.1.19  P-P09
10.1.1.20  P-P10

Unfortunately in this special case it will be a little more complex than that. :wink:

BTW: Please format your code as code here in the forum using the code tag button (pre) provided on the icon bar of the post editor. Thanks.

$IP = Get-Content -Path .\ip.txt
$Name = Get-Content -Path .\name.txt

for ($i = 0; $i -lt $IP.Count; $i++) {
    [PSCustomObject]@{
        IP = $IP[$i]
        Name = $Name[$i]
    }
}

Regardless of that: you might start with learning the very basics of Powershell first. That will save you from a lot of missunderstandings, wasted time and frustrations. :wink:

Hey Olaf ,

Thanks for your answer and your suggestion. I think I will , however , I think I still will post my question here if I meet a problem that I don’t known how to do that in my job , maybe it’s because I haven’t learn that top in the whole learning process or I can’t get an answer from internet.

BR