0
我有一个PowerShell脚本,它可以获取目录中的文件夹列表,并将最新的.bak文件并将其复制到另一个目录中。Powershell - 列出目录中的所有文件夹,拉动每个文件夹中的最新.bak文件,将其压缩,将其复制到目录
有两个文件夹,我不希望它寻找.bak文件。我如何排除这些文件夹?我已经尝试了多种方式的排除陈述,我没有任何运气。
我想忽略的文件夹是“新建文件夹”和“新文件夹1”
$source = "C:\DigiHDBlah"
$filetype = "bak"
$list=Get-ChildItem -Path $source -ErrorAction SilentlyContinue
foreach ($element in $list) {
$fn = Get-ChildItem "$source\$element\*" -Include "*.$filetype" | sort LastWriteTime | select -last 1
$bn=(Get-Item $fn).Basename
$CompressedFile=$bn + ".zip"
$fn| Compress-Archive -DestinationPath "$source\$element\$bn.zip"
Copy-Item -path "$source\$element\$CompressedFile" -Destination "C:\DigiHDBlah2"
}
谢谢!