Blog Post

#PowershellBasics: Multi-line commands

,

When I’m sharing code one of the things I hate most is having a scroll bar along the bottom. I want ya’ll to be able to see all of the code at once. Or at most have to do a bit of scrolling up and down. In my last couple of posts I had some lines of code that were a bit longer and scroll bar started annoying me enough that I decided to figure out how to fix it. You know, it’s kind of funny how much I learn through being annoyed at something enough that I decide to fix it. Anyway, this would be easy enough for me to do in T-SQL. But Powershell? I had no clue.

This is what it looked like when I first wrote this particular line of code.

Get-Service | Where-Object {$_.Status -eq "Running"} | Select-Object Status, Name, DisplayName | Export-Csv -Path C:tempServices.csv -Delimiter '|'

So I spent some time and looked up how (it didn’t really take that long, but I did have to look it up.)

Get-Service | Where-Object {$_.Status -eq "Running"} | `
    Select-Object Status, Name, DisplayName | `
    Export-Csv -Path C:tempServices.csv -Delimiter '|'

That’s what it looks like now. Much better right? Nice and easy to read. And all it takes is the ` character at the end of the line that you are wrapping. To me it looks like a spec of dirt on my screen but basically it’s a single quote leaning from left to right. Turns out it’s even called a backtick.

I’ll be honest, this is one of those posts where the thought “This is way to simple, it’s not worth posting” went through my head. That said, I did have to look the information up, and I’m absolutely certain I’m not the only one. So there you go. One more place the information can be found.

Original post (opens in new tab)
View comments in original post (opens in new tab)

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating