Newlines ignored in Powershell script output

I’m creating some runbooks with Powershell scripts to collect info on sites and databases, and writing them out to the Task Log. Unfortunately when I put any lines inside a code segment such as a foreach, the output all appears on one line no matter if I use Write-Host, Write-Output, or just a variable. Newlines are just ignored. Is there any way to get newlines to appear so I don’t have to go through the extra steps of formatting the info and emailing it?

For instance:
Write-Host “one line”
Foreach ($app in $apps) {
Write-Host $app.name
}

Would output:
oneline
app1 app2 app3

And that’s even if I put multiple Write-Host commands inside the foreach loop.

Looks like the previous step that was collecting data had objects inside of that $apps variable, which is why it wasn’t displaying properly. All good now!

1 Like

Good morning @tim.bunch,

Thank you for contacting Octopus Support and welcome back to the forums.

Sorry to hear you were struggling with a PowerShell script but its great you managed to sort it, thank you for posting up what the issue was too as it helps other customers if they run into the same issue.

Reach out in future if you need anything else from us as we are always on hand to help!

Kind Regards and Happy Deployments,
Clare