在Powershell中循环遍历多个Active Directory Ou

时间:2014-06-06 01:52:23

标签: powershell

如何在Active Directory中搜索多个OU。假设不同用户有4个OU,并且只需要搜索4个中的3个。 目前我使用以下内容搜索一条路径,如何将其展开以搜索多个OU。

$OU='AD Path'
Get-ADUser -SearchBase $OU -Properties Lastlogondate -filter {lastlogondate -lt $DisableDays}

1 个答案:

答案 0 :(得分:1)

看起来-searchbase需要<string>,所以你需要循环遍历OU。

以下查询将获取每个OU中的用户:

$OU=@('cn=users,dc=xyz,dc=com','ou=companyusers,dc=xyz,dc=com')
$ou | foreach { get-aduser -searchbase $_ ...}