Powershell Best Practice #23: Avoid the horizontal scrolling (too long one-liners commands)

By | October 10, 2015

Best Practice: You should avoid the need to use the horizontal scrolling in scripts to keep longs commands more readable.

Explanation: If you write the previous command inside a script, it will be definitely not useful to read.

There are several issues :

  • If I want to see this command, I need to use the horizontal scrolling
  • It is harder to read, update and debug
  • If I have an add-on (ex: CIM Explorer), I could need to close that to temporarily increase the witdh view

Example 1 (with no pipeline)

horizontal-scrolling-bar-ise

A better approach is to use splatting:

horizontal-scrolling-bar-ise-splatting

Example 2 (with pipeline)

horizontal-scrolling-bar-ise-2-net-framework

And now see the difference here, it is much easier to read.

horizontal-scrolling-bar-ise-2-net-framework-alternatives

Note: With ISESteroids, you have the feature “Toggles word wrap”:

toggles-word-wrap

toggles-word-wrap-isesteroids


previous-button

Leave a Reply

Your email address will not be published. Required fields are marked *