Working with long lines
There are several techniques that can be used when writing scripts to avoid excessively long lines of code. The goal is to avoid needing to scroll to the right when reviewing code. A secondary goal is to avoid littering a script with the backtick (grave accent) character, '
, which can be difficult to see for some.
This book continually makes use of these techniques to try and present examples without wrapping across lines. For example, one of the examples from ShouldProcess
uses three arguments inside an if
statement condition:
if ($PSCmdlet.ShouldProcess(
'Message displayed using WhatIf',
'Warning: Deleting SomeObject',
'Question: Are you sure you want to do continue?')
) {
Write-Host 'Deleting SomeObject' -ForegroundColor Cyan
}
This takes advantage of the ability to add a line break after (
and ,
. The example may be harder to read if all values are squashed onto a single...