Powershell 排除文件夹以减小图像的大小

Powershell 排除文件夹以减小图像的大小,powershell,Powershell,我有一个减少文件夹和子文件夹中图像大小的脚本。但是,我想排除一些文件夹 我找到了参数$source\u listephotos=Get ChildItem$source-Recurse | where{$\u.FullName-notmatch$exclude\u list},但它允许排除一个文件夹而不是多个文件夹 $source = "U:\TEST\Compression\images" $exclude_list = @('Imprimerie') $source_listephotos

我有一个减少文件夹和子文件夹中图像大小的脚本。但是,我想排除一些文件夹

我找到了参数
$source\u listephotos=Get ChildItem$source-Recurse | where{$\u.FullName-notmatch$exclude\u list}
,但它允许排除一个文件夹而不是多个文件夹

$source = "U:\TEST\Compression\images"
$exclude_list = @('Imprimerie')

$source_listephotos = Get-ChildItem $source -Recurse | where {$_.FullName -notmatch $exclude_list}

您有解决方案吗?

您可以使用get childitem上的排除列表

$source_listephotos = Get-ChildItem $source -Recurse -exclude $exclude_list| where {$_.FullName}
操作符使用正则表达式(regex),因此修复代码的最简单解决方案是在文件夹列表中使用管道符号

$source = "U:\TEST\Compression\images"
[regex] $exclude_list = “(Imprimerie|TestAnotherName)”

$source_listephotos = Get-ChildItem $source -Recurse | where {$_.FullName -notmatch $exclude_list}

将您的excludelist创建为如下字符串:'impimerie | impimerie1abc'…我还建议在$上进行匹配,因为fullname将匹配整个路径。考虑将您的WHERE子句与$.PSISPOSTER-EQ$TrtrueEnter复制,谢谢您的帮助!!where子句已过时,为了将列表与正则表达式变量区别开来,请参见
$exclude_list=@('impimerie','otherfoler')
谢谢您的回答。我已经试过了,我的脚本可以按照我的意愿工作