powershelltext-filesout-gridview

Powershell: Out-gridview with text files


I have two text files, let's say containing:

1.txt:

1
2
3
4
5
6

2.txt:

a
b
c
d
e
f

I'm trying to read the files, then output the results to Out-Gridview (each file in it's own column) :

1 a
2 b
3 c
4 d
5 e
6 f

I'm trying :

$list1= gc 1.txt 
$list2= gc 2.txt



$list1 | Add-Member -Name "LIST 2" -MemberType NoteProperty -Value $liste2


$list1 | out-gridview -wait

But all i get is :

enter image description here

How can i have each text file read then output to columns in gridview? Thank you so much I can't figure this out...


Solution

  • Create a hashtable when you only have two columns. Like that:

    $a = 1,2,3,4
    $b = "a","b","c","d"
    $hashtable = @{}
    
    for($i = 0;$a.Count -gt $i;$i++){
        $hashtable.Add($a[$i],$b[$i])
    }
    
    $hashtable | Out-GridView
    

    if you have more than two columns,create a custom object