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.

petezurich
  • 9,280
  • 9
  • 43
  • 57
Matthew Darens
  • 129
  • 2
  • 8
  • That's actually not a proper question for SO. You should search for "Powershell" and "line break" or "line continuation". – Olaf Apr 10 '18 at 14:09
  • You can always insert line breaks where PowerShell `expects` a continuation i.e. before `})` or behind `|{(,` –  Apr 10 '18 at 14:47
  • Use a backtick (`) to make a single line mulitple lines - see https://stackoverflow.com/questions/3235850/how-to-enter-a-multi-line-command. You can write a script to do this if you want, which could be a good way to learn PowerShell. – NextInLine Apr 10 '18 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. – NextInLine Apr 10 '18 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. – Olaf Apr 10 '18 at 21:18
  • @Olaf Can you be more specific about what you don't like about this question? I don't see anything in https://stackoverflow.com/help/how-to-ask that this question violates - are you referring to something else? – NextInLine Apr 10 '18 at 22:00

1 Answers1

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.

srbrills
  • 1,451
  • 2
  • 13
  • 33
  • 1
    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 – HeedfulCrayon Apr 10 '18 at 16:43