计算Powershell数组中的行数

时间:2013-07-03 11:59:05

标签: powershell

我编写了以下脚本,以返回域中所有空的组织单位的名称。

我希望脚本通过计算返回的行数来告诉我最后的空OU总数。我已尝试为$array分配New-Object,并在脚本末尾添加各种版本的$array.count| Measure-Object,但所有版本都返回0

Get-ADOrganizationalUnit -Filter * |
foreach {
    $o = Get-ADObject -filter * -searchbase $_.distinguishedname -searchscope 1
    $total = ($o | Measure-Object).Count 
    New-Object psobject -Property @{
        Name=$_.distinguishedname
        } |
        where-object {$total -le "0"}
    }

1 个答案:

答案 0 :(得分:1)

$ou = Get-ADOrganizationalUnit -Filter * | 
Where-Object { -not (Get-ADObject -SearchBase $_.DistinguishedName -Filter * -SearchScope OneLevel) }


# get the count
$ou|measure

$list OUs
$ou