views:

627

answers:

2

I need to echo a series of elements of an array in PS but provide various delimiters between the elements, so Im using;

Add-Content -Path $tempInputDir\testoutput.log -value ($($fields[0]) + "   "+ 
$($fields[1]) + "   " + $($fields[2]) + " " + $($fields[3])+ " "+ 
$($fields[15]) + "  " + $($fields[17])) 
}

So I need to be able to add tabs and space characters, as you can see from the code above ive just done this by physically adding tabs and spaces in between double quotes but Im sure this will cause problems down the line.

Whats the correct way to echo this characters to a file, i read somewhere that "'t" could be used but that doesn't seem to work?

+4  A: 

You can use `t for a tab character in a double quoted string. You can also simplify the above to:

"$($fields[0])   $($fields[1])   $($fields[2]) $($fields[3])  $($fields[15])  $($fields[17])" | Add-Content $tempInputDir\testoutput.log
Keith Hill
+3  A: 

To join the nominated fields together with tabs:

[string]::join("`t", (0,1,2,3,15,17 | % {$fields[$_]}))
dangph