Write to a text file with append in a Table format using PowerShell
In PowerShell, you can use Add-Content
to write data to a file.
Example
The below example adds a dummy data with append to a text file in a table format using Add-Content to write data, the n (to add a new line)
and the t (to write a tab)
# define the file path
$filepath = "c:\debug.too.txt"
#build Header
Add-Content $filepath "TaskID`t| TaskName`t"
#write data
for($i=0;$i -lt 10;$i++)
{
Add-Content $filepath "`n$i`t| debug.to $i`t"
}
#open the file
start $filepath
Output
Note: If you would like to write data in a table format using PowerShell, and there is no need to use a text file, it would be preferred to instead use a CSV file as mentioned in this example PowerShell access to the path is denied.