title: What is the recommended coding style for PowerShell?
body: <p>Is there any recommended coding style how to write PowerShell scripts?</p>
  
  <p>It's <strong>not</strong> about how to structure the code (how many functions, if to use module, ...). It's about '<strong>how to write the code so that it is readable</strong>'.</p>
  
  <p>In programming languages there are some <strong>recommended coding styles</strong> (what to <em>indent</em>, how to indent - spaces/tabs, where to make <em>new line</em>, where to put <em>braces</em>,...), but I haven't seen any suggestion for PowerShell.</p>
  
  <p>I'm interested particularly in:</p>
  
  <hr>
  
  <p><strong>How to write parameters</strong></p>
  
  <pre><code>function New-XYZItem
    ( [string] $ItemName
    , [scriptblock] $definition
    ) { ...
  </code></pre>
  
  <p>(I see that it's more like 'V1' syntax)</p>
  
  <p>or</p>
  
  <pre><code>function New-PSClass  {
    param([string] $ClassName
         ,[scriptblock] $definition
    )...
  </code></pre>
  
  <p>or (why to add empty attribute?)</p>
  
  <pre><code>function New-PSClass  {
    param([Parameter()][string] $ClassName
         ,[Parameter()][scriptblock] $definition
    )...
  </code></pre>
  
  <p>or (other formatting I saw maybe in Jaykul's code)</p>
  
  <pre><code>function New-PSClass {
    param(
          [Parameter()]
          [string]
          $ClassName
          ,
          [Parameter()]
          [scriptblock]
          $definition
    )...
  </code></pre>
  
  <p>or ...?</p>
  
  <hr>
  
  <p><strong>How to write a complex pipeline</strong></p>
  
  <pre><code>Get-SomeData -param1 abc -param2 xyz | % {
      $temp1 = $_
      1..100 | % {
        Process-somehow $temp1 $_
      }
    } | % {
      Process-Again $_
    } |
    Sort-Object -desc
  </code></pre>
  
  <p>or (name of cmdlet on new line)</p>
  
  <pre><code>Get-SomeData -param1 abc -param2 xyz |
    % {
      $temp1 = $_
      1..100 |
        % {
          Process-somehow $temp1 $_
        }
    } |
    % {
      Process-Again $_
    } |
    Sort-Object -desc |
  </code></pre>
  
  <p>And what if there are <code>-begin</code>, <code>-process</code>, and <code>-end</code> parameters? How do I make it the most readable?</p>
  
  <pre><code>Get-SomeData -param1 abc -param2 xyz |
    % -begin {
       init
    } -process {
       Process-somehow2 ...
    } -end {
       Process-somehow3 ...
    } |
    % -begin {
    } ....
  </code></pre>
  
  <p>or</p>
  
  <pre><code>Get-SomeData -param1 abc -param2 xyz |
    %  `
      -begin {
        init
      } `
      -process {
        Process-somehow2 ...
      } `
      -end {
        Process-somehow3 ...
      } |
    % -begin {
    } ....
  </code></pre>
  
  <p>The indentation is important here and what element is put on new line as well.</p>
  
  <hr>
  
  <p>I have covered only questions that come on my mind very frequently. There are some others, but I'd like to keep this Stack&nbsp;Overflow question 'short'.</p>
  
  <p><strong>Any other suggestions are welcome.</strong></p>