How to properly -filter multiple strings in a PowerShell copy script

前端 未结 4 510
暗喜
暗喜 2020-11-29 00:01

I am using the PowerShell script from this answer to do a file copy. The problem arises when I want to include multiple file types using the filter.

Get-Chi         


        
4条回答
  •  余生分开走
    2020-11-29 00:41

    -Filter only accepts a single string. -Include accepts multiple values, but qualifies the -Path argument. The trick is to append \* to the end of the path, and then use -Include to select multiple extensions. BTW, quoting strings is unnecessary in cmdlet arguments unless they contain spaces or shell special characters.

    Get-ChildItem $originalPath\* -Include *.gif, *.jpg, *.xls*, *.doc*, *.pdf*, *.wav*, .ppt*
    

    Note that this will work regardless of whether $originalPath ends in a backslash, because multiple consecutive backslashes are interpreted as a single path separator. For example, try:

    Get-ChildItem C:\\\\\Windows
    

提交回复
热议问题