title: How can I propagate parameters from my script into internal function calls?
body: <p>I'm writing a script in PowerShell and I need to pass an optional parameter that I declared as a parameter of my script into a function.</p>
  
  <p>For instance, this could be a <code>Example.ps1</code> file:</p>
  
  <pre><code>[CmdletBinding()]
  Param(
      [string] $Param1,
      [string] $Param2,
      [string] $Param3,
      [string] $ComputerName
  )
  
  #... code that uses the first 3 parameters ...
  
  # Here, I need to pass the 'ComputerName' parameter along:
  Start-DscConfiguration -Path 'somePath -ComputerName $ComputerName -Wait
  </code></pre>
  
  <p>I tried two approaches using splatting, but I'm not too happy with either of them. The first one is to use the <code>PSBoundParameters</code> hashset like this:</p>
  
  <pre><code>PSBoundParameters.Remove('Param1');
  PSBoundParameters.Remove('Param2');
  PSBoundParameters.Remove('Param3');
  Start-DscConfiguration -Path 'somePath @PSBoundParameters -Wait
  </code></pre>
  
  <p>And the second is by using a new hashtable, with the required arguments:</p>
  
  <pre><code>$dscParameters = @{
      Path = 'somePath'
  };
  if (-Not [string]::IsNullOrEmpty($ComputerName))
  {
      $dscParameters.Add('ComputerName', $ComputerName);
  }
  
  Start-DscConfiguration @dscParameters -Wait
  </code></pre>
  
  <p>Is there a more elegant way of propagating my parameters to the functions that I call inside of my script? Perhaps if there was a cleaner way of constructing the hashset without including the <code>ComputerName</code> key if it was not supplied or something.</p>
  
  <p>UPDATE:</p>
  
  <p>Note that I can't just always redirect it, since it is optional and thus can be empty. If I pass an empty <code>ComputerName</code> to <code>Start-DscConfiguration</code> in this case, it will complain that it could not find computer "".</p>