Похоже, у вас уже есть строковый массив в качестве вывода, что приводит к таблице с фиксированной шириной.
Ниже я использую Here-String для имитации этого массива
$output = @"
[ ID] Interval Transfer Bandwidth
[ 4] 0.00-1.00 sec 11.4 MBytes 95.4 Mbits/sec
[ 4] 1.00-2.00 sec 11.2 MBytes 94.2 Mbits/sec
[ 4] 2.00-3.00 sec 11.2 MBytes 94.3 Mbits/sec
[ 4] 3.00-4.00 sec 11.2 MBytes 94.5 Mbits/sec
[ 4] 4.00-5.00 sec 11.2 MBytes 94.2 Mbits/sec
[ 4] 5.00-6.00 sec 11.2 MBytes 94.4 Mbits/sec
[ 4] 6.00-7.00 sec 11.2 MBytes 94.4 Mbits/sec
[ 4] 7.00-8.00 sec 11.2 MBytes 94.3 Mbits/sec
[ 4] 8.00-9.00 sec 11.2 MBytes 94.2 Mbits/sec
[ 4] 9.00-10.00 sec 11.2 MBytes 94.5 Mbits/sec
"@ -split '\r?\n'
$result = for ($i = 1; $i -lt $output.Count; $i++) {
if ($output[$i] -match '^(?<id>.{6})(?<interval>.{19})(?<transfer>.{13})(?<bandwidth>.*)') {
[PsCustomObject]@{
'ID' = $matches['id'].Trim('[] ')
'Interval' = $matches['interval'].Trim()
'Transfer' = $matches['transfer'].Trim()
'BandWidth' = $matches['bandwidth'].Trim()
}
}
}
# output on screen
$result
#output to CSV file
$result | Export-Csv -Path 'X:\table.csv' -NoTypeInformation
Результат:
ID Interval Transfer BandWidth
-- -------- -------- ---------
4 0.00-1.00 sec 11.4 MBytes 95.4 Mbits/sec
4 1.00-2.00 sec 11.2 MBytes 94.2 Mbits/sec
4 2.00-3.00 sec 11.2 MBytes 94.3 Mbits/sec
4 3.00-4.00 sec 11.2 MBytes 94.5 Mbits/sec
4 4.00-5.00 sec 11.2 MBytes 94.2 Mbits/sec
4 5.00-6.00 sec 11.2 MBytes 94.4 Mbits/sec
4 6.00-7.00 sec 11.2 MBytes 94.4 Mbits/sec
4 7.00-8.00 sec 11.2 MBytes 94.3 Mbits/sec
4 8.00-9.00 sec 11.2 MBytes 94.2 Mbits/sec
4 9.00-10.00 sec 11.2 MBytes 94.5 Mbits/sec