使用powershell从所有子文件夹中删除具有许多特定目录名称的文件夹和内容

使用powershell从所有子文件夹中删除具有许多特定目录名称的文件夹和内容,powershell,directory,subdirectory,Powershell,Directory,Subdirectory,我正在使用win 10和Power Shell V5.1.18362.1110 我在一个目录下的多个子目录中有数百个重复的命名子目录,我需要删除特定的目录及其内容,手动查看每个目录非常耗时。如果它可以引用一个我可以输入的文本文件,一次只列出一行,那就太好了。(或者你的建议) 我试过: $source="h:\Batch Remove TEST" #location of directory to search $strings=@("1306001", &

我正在使用win 10和Power Shell V5.1.18362.1110

我在一个目录下的多个子目录中有数百个重复的命名子目录,我需要删除特定的目录及其内容,手动查看每个目录非常耗时。如果它可以引用一个我可以输入的文本文件,一次只列出一行,那就太好了。(或者你的建议)

我试过:

$source="h:\Batch Remove TEST" #location of directory to search
$strings=@("1306001", "1311001")

cd ($source); get-childitem -Include ($strings) -Recurse -force | Remove-Item -Force –Recurse
它将从第一个子目录中删除这两个文件夹,但不会从随后的子目录中删除

它返回了以下错误:

Get ChildItem:访问被拒绝
在H:\Batch Remove TEST\cm.ps1:1 char:1
+获取子项-包括13060011311001-递归-强制|移除现场。。。
+CategoryInfo:NotSpecified:(:)[Get ChildItem],UnauthorizedAccessException
+FullyQualifiedErrorId:System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetChildItemCommand
我被难住了。
谢谢大家!

看起来您无法删除当前打开的powershell文件。这些目录及其文件位于powershell文件目录下。它在第一个子目录上运行良好,然后在检查下一个子目录之前停止。我需要它检查powershell文件下的所有子目录,删除以$string表示的目录和文件,而不仅仅是第一个子目录。非常感谢。