How can I use PowerShell's -filter parameter to exclude values/files?

后端 未结 2 1508
暗喜
暗喜 2021-02-19 21:00

I\'m currently running a PowerShell (v3.0) script, one step of which is to retrieve all the HTML files in a directory. That works great:

$srcfiles = Get-ChildItem

相关标签:
2条回答
  • 2021-02-19 21:25

    I am a little newer to PowerShell, but could you pipe to the where command?

    $srcfiles = Get-ChildItem $srcPath | where-object {$_.extension -ne "*.htm*"}
    

    I am not sure what the actually property you would use in place "extension" is though.

    0 讨论(0)
  • 2021-02-19 21:27

    -Filter is not the right way. Use the -exclude parameter instead:

    $srcfiles = Get-ChildItem $srcPath -exclude *.htm*
    

    -exclude accepts a string[] type as an input. In that way you can exclude more than one extension/file type as follows:

     $srcfiles = Get-ChildItem $srcPath -exclude *.htm*,*.css,*.doc*,*.xls*
    

    ..And so on.

    0 讨论(0)
提交回复
热议问题