Break Down a PowerShell Script Into Multiple Lines

In this blog post, I will show you how to break a PowerShell script to multiple lines.

Sometimes when writing a PowerShell script, there is a need to make the code extra clear and understood.

Backtick

For that reason PowerShell allows us to use a backtick   ` and start a new like of code without breaking our code.

The format to use a backtick is to start with space, backtick and enter.

Blow, is an example of how I break a cmdlet into a few lines.

install-ADDSForest `
-DomainName "corp.ntweekly.com" `
-DomainNetbiosName "ntweekly" `
-SafeModeAdministratorPassword $pass`
-InstallDns:$true `
-NoRebootOnCompletion:$false `
-SysvolPath "C:\Windows\SYSVOL" `
-Force:$true

 

 

One Reply to “Break Down a PowerShell Script Into Multiple Lines”

  1. Hi,
    Please, avoid using backticks, prefer Splating.Splat is easy to build,easy to read, splat has not the convenients of using backticks.
    Backtips should be use in some specifics cases only. See : https://get-powershellblog.blogspot.com/2017/07/bye-bye-backtick-natural-line.html

    For my part, when I have a cmdlet with more than 4-5 parameters, I’m using splat. Splat only or splat + one additionnal parameter. Splat in this case, is for common parameters.

    regards
    Olivier

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.