How to add a tab to a text file
19,002
Solution 1
"`t" will output a tab character.
Solution 2
Try something like this:
"{0}`t{1}`t{2}`t{3}" -f $server, $servicename, $status, $startname |
Out-File "C:\path\to\output.txt" -Append
If your input data is a list of objects, you may also be able to use Export-Csv
or ConvertTo-Csv
:
... | ConvertTo-Csv -Delimiter "`t" -NoTypeInformation |
Out-File "C:\path\to\output.txt" -Append
Author by
Khanh Le
Updated on June 04, 2022Comments
-
Khanh Le almost 2 years
I am running a
for
loop that would query for certain services and then output the services and their selected properties to a text file on each separate line where each property is separated by a tab, but I haven't figured out how to add a tab to a text file.For instance, this is current set of strings in my code:
write-output $server, $servicename, $status, $startname | out-file -append output.txt
I would like to append the above string to output.txt, so it would appear like this:
server1 <tab> servername <tab> status <tab> startname server2 <tab> servername <tab> status <tab> startname