I need to create a PowerShell table with multiple columns and in each column, I need to push different data, a succeeded to create the table but the solution looks like that:
I want that each column will start in the first index
This is the code:
$tabName = "SampleTable"
#Create Table object
$table = New-Object system.Data.DataTable “$tabName”
$groups = 'prod', 'env', 'app'
$vms = '1', '2', '3'
foreach ($group in $groups)
{
$col = New-Object system.Data.DataColumn $group,([string])
$table.columns.add($col)
foreach ($vm in $vms)
{
$row = $table.NewRow()
$row.$group = $vm
$table.Rows.Add($row)
}
}
$table # | Export-Csv $path -NoTypeInformation