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
""doing in the function? that is what echoing the blank line\r\n""was originally echoing a blank line to the console. It's a bad habit of mine. I know the "what", but I'm trying to figure out the "why".get-help about_return. Anything that is not captured in a function will get returned. use write-host and you won't have this problem