使用PowerShell我想检查一个目录(全名在$PathOutput
),如果它包含其他目录。如果此路径不包含其他目录,我希望变量$FailedTests
具有字符串'none',否则变量$FailedTests
应该包含每个找到的目录(非递归),可以是不同的行,也可以是逗号分隔的或任何其他目录。如何获取目录列表或'无'?
我曾尝试下面的代码:
$DirectoryInfo = Get-ChildItem $PathOutput | Measure-Object
if ($directoryInfo.Count -eq 0)
{
$FailedTests = "none"
} else {
$FailedTests = Get-ChildItem $PathOutput -Name -Attributes D | Measure-Object
}
,但它会生成以下错误:
Get-ChildItem : A parameter cannot be found that matches parameter name 'attributes'. At D:\Testing\Data\Powershell\LoadRunner\LRmain.ps1:52 char:62 + $FailedTests = Get-ChildItem $PathOutput -Name -Attributes <<<< D | Measure-Object + CategoryInfo : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
我使用PowerShell 2.0的Windows Server 2008上
我宁愿该解决方案使用Get-ChildItem
或仅使用一次。
非常感谢,正是我需要的,它也工作得很好! – Alex