I've recently broken into some of the subtler nuances of PowerShell, and noticed something I cannot avoid involving the return of a new line at the start of a string using this mundane function...
Function Why() {
""
return "Well I tried."
}
This returns "\r\nWell I tried".
Write-Host "Starting test."
$theBigQuestion= Why
Write-Host $theBigQuestion
Write-Host "Ending test."
This will output the following:
Starting test.
Well I tried.
Well I tried.
Ending test.
Now, this appears PowerShell is concatenating one output with another. But... why? What makes it think that I wanted the blank line to be part of the return statement? I (perhaps erroneously) like to use lines like this as shorthand, or to examine variables more closely for debugging purposes.
Related: Function return value in PowerShell