Don’t do that: I often see people who use multiple lines “Write-Host” to add new lines on the screen (as Write-Host send the output only to the screen).
1 2 3 |
Write-Host Write-Host "Output" Write-Host |
Do that: You can use the special character `n for new line: "`nOutput`n"
The result is the same but requires only one line.
Note: You can use Here-String in case you have to deal with multiple special characters:
1 2 3 4 5 |
$hereString = @" Output "@ |
Pingback: Don't do that #2 : Multiple lines to read variables - Powershell Guru
Pingback: Don't do that #4 : Don't ask the user to write in upper case - Powershell Guru
Shouldn’t Write-Host almost always be Write-Output instead?
Hi Eric,
Exactly. Personally, I never use Write-Host (I consider it has many inconvenients and limitations) in any PowerShell code I develop.
But this is only my own opinion and some beginners prefer to use Write-Host (it is their own choice).
The most important here is the logical to understand and propose different alternatives (although I sometimes don’t agree with all of them but always good to know they exist).
Regards,
Steve