Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Custom tables and PSobject

$
0
0

Hi, so im messing with ps hash tables and custom tables i am looking for an alternative way of outputting them in the right format below, maybe someone could show me an easier way so this is what i typically use that works:

$objcol = @()
$data1 = "a1","a2","a3","a4"
$data2 = "b1","b2","b3","b4"
$data1 |foreach{
$obj = New-Object -Type PSObject
$Obj | Add-Member -MemberType NoteProperty -Name "data1" -Value "$_"
$objcol += $obj
}
$i = 0
$data2 |foreach{
$objcol[$i++] | Add-Member -MemberType NoteProperty -Name "data2" -Value "$_"
}
$objcol

result

data1                                                    data2                                                  
-----                                                    -----                                                  
a1                                                       b1                                                     
a2                                                       b2                                                     
a3                                                       b3                                                     
a4                                                       b4 

is there another way of doing this without using the $i++ incase there is different number of results in each variable?




Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>