搜索存在或缺失的目录结构和报表文件夹



我正在寻找一些帮助,在PowerShell中编写代码以检查和报告。

我想C:MyDataMyCustomerNames搜索文件夹MyTestsMyProductsMyReturns,然后报告C:MyDataMyCustomerNamesMyTests is PresentC:MyDataMyCustomerNamesMyProducts is Missing

我知道代码Test-Path C:MyDataMyCustomerNamesMyProducts可以工作,但我也想测试*.xml*.docx等。 另外,路径中唯一是变量的部分是 MyCustomerNames .

如果你能指出一些可行的东西,那就太棒了,或者提供一个比我提供的更能说明的例子。

请,谢谢!

扩展苏

打柳的建议。将位置保存在数组中,然后使用 foreach 语句对数组中的每个值运行循环。您可以在 if 语句中使用Get-ChildItem来搜索这些目录并评估它们是否存在。

$folders = "MyTests", "MyProducts", "MyReturns"
foreach ($folder in $folders) {
    if (Get-ChildItem -Path "C:MyDataMyCustomerNames" -Filter $folder -Directory) {
        "$folder exists"
    } else {
        "$folder does not exist"
    }
}

最新更新