使用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