【发布时间】:2021-11-26 18:46:16
【问题描述】:
我正在编写一个脚本来识别文件夹中受密码保护的 pdf 文件。如果 pdf 受密码保护,那么它将将该文件夹以及所有文件和子文件夹移动到另一个文件夹。我可以让脚本与副本一起正常工作,但似乎正在读取“加密”文件的流式阅读器正在锁定文件,阻止我移动文件。我一直在尝试关闭流式阅读器的方法,但到目前为止没有任何效果。任何帮助将不胜感激。
$Source = 'sourcefolder'
$Dest = 'Destinationfolder'
Get-ChildItem -Path $Source -Directory |
ForEach-Object {
If (Get-ChildItem -Path $_.FullName -filter *.pdf | where {
$_.OpenText().ReadToEnd().Contains("Encrypt") -eq $true }) {
Move-Item -Path $_.FullName -Destination $Dest -Force -Verbose
}
}
【问题讨论】:
标签: powershell encryption passwords streamreader opentext