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 following command inside a script, it will be definitely not useful to read.

There are several issues :

  • If you want to see this command, you need to use the horizontal scrolling
  • It is harder to read, update and debug
  • If you have an add-on (ex: CIM Explorer), you could need to close that to temporarily increase the width 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.