title: Getting all Named Parameters from Powershell including empty and set ones
body: <p>I'm trying to find a way to get all parameter information from a powershell script. Ex script:</p>
  
  <pre><code>function test()
  {
      Param(
          [string]$foo,
          [string]$bar,
          [string]$baz = "baz"
      )
  
      foreach ($key in $MyInvocation.BoundParameters.keys)
      {
          write-host "Parameter: $($key) -&gt; $($MyInvocation.BoundParameters[$key])"
      }
  }
  test -foo "foo!"
  </code></pre>
  
  <p>I'd like to get the values of <code>$bar</code> and <code>$baz</code> in a dynamic way without knowing the names of the parameters ahead of time.</p>
  
  <p>I've looked through <code>$MyInvocation</code> properties and methods but I don't see anything besides parameters that are set/passed.</p>
  
  <p><strong>Update 1:</strong></p>
  
  <p>I'm close to getting it with:</p>
  
  <pre><code>function test()
  {
      Param(
          [string]$foo,
          [string]$bar,
          [string]$baz = "baz"
      )
      foreach($var in (get-variable -scope private))
      {
          write-host "$($var.name) -&gt; $($var.value)"
      }
  }
  test -foo "foo!"
  </code></pre>
  
  <p>If i could filter out the script parameters vs the default parameters I would be good to go. </p>
  
  <p><strong>Update 2:</strong>
  The final working solution looks like this:</p>
  
  <pre><code>function test {
      param (
            [string] $Bar = 'test'
          , [string] $Baz
          , [string] $Asdf
      )
      $ParameterList = (Get-Command -Name $MyInvocation.InvocationName).Parameters;
      foreach ($key in $ParameterList.keys)
      {
          $var = Get-Variable -Name $key -ErrorAction SilentlyContinue;
          if($var)
          {
              write-host "$($var.name) &gt; $($var.value)"
          }
      }
  }
  
  test -asdf blah;
  </code></pre>