title: Why does pipeline parameter cause error when combined with PSDefaultParameterValues?
body: <p>My powershell function should accept a list of valid paths of mixed files and/or directories either as a named parameter or via pipeline, filter for files that match a pattern, and return the list of files.</p>
  <p><code>$Paths = 'C:\MyFolder\','C:\MyFile'</code></p>
  <p>This works: <code>Get-Files -Paths $Paths</code> This doesn't: <code>$Paths | Get-Files</code></p>
  <pre><code>$PSDefaultParameterValues = @{
      &quot;Get-Files:Paths&quot;   = ( Get-Location ).Path
  }
  
  [regex]$DateRegex = '(20\d{2})([0-1]\d)([0-3]\d)'
  [regex]$FileNameRegex = '^term2-3\.7_' + $DateRegex + '\.csv$' 
  
  Function Get-Files {
      [CmdletBinding()]
      [OutputType([System.IO.FileInfo[]])]
      [OutputType([System.IO.FileInfo])]
      param (
          [Parameter(
              Mandatory = $false, # Should default to $cwd provided by $PSDefaultParameterValues
              ValueFromPipeline,
              HelpMessage = &quot;Enter filesystem paths that point either to files directly or to directories holding them.&quot;
          )]
          [String[]]$Paths
      )
      begin {
          [System.IO.FileInfo[]]$FileInfos = @()
          [System.IO.FileInfo[]]$SelectedFileInfos = @()
      }
      process { foreach ($Path in $Paths) {
          Switch ($Path) {
              { Test-Path -Path $Path -PathType leaf } {
                  $FileInfos += (Get-Item $Path)
              }
              { Test-Path -Path $Path -PathType container } {
                  foreach ($Child in (Get-ChildItem $Path -File)) {
                      $FileInfos += $Child
                  }
              }
              Default {
                  Write-Warning -Message &quot;Path not found: $Path&quot;
                  continue
              }
          }
          $SelectedFileInfos += $FileInfos | Where-Object { $_.Name -match $FileNameRegex }
          $FileInfos.Clear()
      } }
      end {
          Return $SelectedFileInfos | Get-Unique
      }
  }
  </code></pre>
  <p>I found that both versions work if I remove the default parameter value. Why?</p>
  <p>Why does passing a parameter via the pipeline cause an error when that parameter has a default defined in PSDefaultParameterValues, and is there a way to work around this?</p>