title: How to properly -filter multiple strings in a PowerShell copy script
body: <p>I am using the PowerShell script from <a href="https://stackoverflow.com/questions/5432290/how-to-use-powershell-copy-item-and-keep-structure">this answer</a> to do a file copy. The problem arises when I want to include multiple file types using the filter. </p>
  
  <pre><code>Get-ChildItem $originalPath -filter "*.htm"  | `
     foreach{ $targetFile = $htmPath + $_.FullName.SubString($originalPath.Length); ` 
   New-Item -ItemType File -Path $targetFile -Force;  `
   Copy-Item $_.FullName -destination $targetFile }
  </code></pre>
  
  <p>works like a dream. However, The problem arises when I want to include multiple file types using the filter. </p>
  
  <pre><code>Get-ChildItem $originalPath ` 
    -filter "*.gif","*.jpg","*.xls*","*.doc*","*.pdf*","*.wav*",".ppt*")  | `
     foreach{ $targetFile = $htmPath + $_.FullName.SubString($originalPath.Length); ` 
   New-Item -ItemType File -Path $targetFile -Force;  `
   Copy-Item $_.FullName -destination $targetFile }
  </code></pre>
  
  <p>Gives me the following error:</p>
  
  <pre><code>Get-ChildItem : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Filter'. Specified method is not supported.
  At F:\data\foo\CGM.ps1:121 char:36
  + Get-ChildItem $originalPath -filter &lt;&lt;&lt;&lt;  "*.gif","*.jpg","*.xls*","*.doc*","*.pdf*","*.wav*",".ppt*" | `
      + CategoryInfo          : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException
      + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.GetChildItemCommand
  </code></pre>
  
  <p>I have various iterations of parentheses, no parentheses, <code>-filter</code>, <code>-include</code>, defining the inclusions as variable (e.g., <code>$fileFilter</code>) and each time get the above error, and always pointing to whatever follows <code>-filter</code>.</p>
  
  <p>The interesting exception to that is when I code <code>-filter "*.gif,*.jpg,*.xls*,*.doc*,*.pdf*,*.wav*,*.ppt*"</code>. There are no errors, but I and get no results and nothing back to the console. I suspect I've inadvertently coded an impicit <code>and</code> with that statement?</p>
  
  <p>So what am I doing wrong, and how can I correct it?</p>