Reputation: 65
so i am trying to display commands for a powershell script for self-use. i am using a txt file as the source of the list. the txt file is formatted as so;
command (* is input)| description
----------------------------------------------------
pack | opens folder pack
c * / cpp * | copies mingw command to compile
code | reveals source
copy * | copies input
Now; i have a function called that prints out this txt file and the function is this;
Function help{
Write-Host (get-content -path {file-path})
}
However, in the terminal, the output looks like this;
command (* is input)| description ---------------------------------------------------- pack | opens folder pack * / cpp * | copies mingw command to compile code
how can i fix this?
Upvotes: 2
Views: 202
Reputation: 437100
Don't use Write-Host
to output data - it is meant for display output.
Write-Host
stringifies the array that Get-Content
outputs, which means space-concatenating its elements, hence the single-line display.Use Write-Output
to output data or, better yet, rely on PowerShell's implicit output feature:
Function help {
# Get-Content's output is implicitly output.
Get-Content -path somefile.ext
}
See this answer for more information.
Upvotes: 1