0

There have only been a couple of times that I needed to understand PowerShell scripts, but they are usually written in one line. I have searched the internet and found that some people convert their multi-line scripts to single-line. For me, as a newbie in PowerShell, it is hard to read those scripts sometimes.

Is there any way to convert large single-line scripts to multi-line scripts?

Any tools would be appreciated. Thank you.

6
  • That's actually not a proper question for SO. You should search for "Powershell" and "line break" or "line continuation". Commented Apr 10, 2018 at 14:09
  • You can always insert line breaks where PowerShell expects a continuation i.e. before }) or behind |{(, Commented Apr 10, 2018 at 14:47
  • Use a backtick (`) to make a single line mulitple lines - see stackoverflow.com/questions/3235850/…. You can write a script to do this if you want, which could be a good way to learn PowerShell. Commented Apr 10, 2018 at 15:36
  • @Olaf This seems like a reasonable SO question - SO is supposed to serve as a repository of knowledge that can show up in Google search results. Commented Apr 10, 2018 at 15:39
  • @NextInLine That's your opinion. But the SO guide lines postulate something else. And your tip to use backticks is (in my opinion) the worst tip you can give for a Powershell novice. Commented Apr 10, 2018 at 21:18

1 Answer 1

1

In any language, sometimes people minify their code, scripts, or payloads. Sometimes there are online tools to 'de-minify' code online, although I don't know if there are ones for PowerShell.

If I ever need to minify or de-minify code manually, I like using Sublime for regex searching and multi-line editing.

https://www.sublimetext.com/

You could use a find and replace using regular expressions (regex), and add new-line characters wherever you wanted. If the script has semicolons, you could search for those and replace each of them with a semicolon followed by a new-line character.

Sublime has a free trial, and doesn't require payment when the trial is over.

Sign up to request clarification or add additional context in comments.

1 Comment

Visual Studio Code is also a great editor when used with the powershell extension. It basically has intellisense for powershell, there are also other extensions such as DevSkim that will skim your powershell code and highlight issues that are not best practice

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.