Reputation: 101
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
Upvotes: 3
Views: 20761
Reputation: 36
Even more flexibility is given working with arrays.
Let's say you've put your information in an array.
$servers[] = array($server, $servicename, $status, $startname);
Then you can implode the values with a tab, like this:
foreach($servers as $server)
echo implode("\t", $server) . "\n";
Upvotes: -1
Reputation: 5349
Apparently you can use ``t` for tab in PowerShell. See Stack Overflow question Writing tabs to a file using PowerShell.
Most languages support \t
though.
Upvotes: 0
Reputation: 200233
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
Upvotes: 5