我编写了以下脚本,以返回域中所有空的组织单位的名称。
我希望脚本通过计算返回的行数来告诉我最后的空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"}
}
答案 0 :(得分:1)
$ou = Get-ADOrganizationalUnit -Filter * |
Where-Object { -not (Get-ADObject -SearchBase $_.DistinguishedName -Filter * -SearchScope OneLevel) }
# get the count
$ou|measure
$list OUs
$ou