简体   繁体   English

Ldap滤波器适用于多欧Powershell

[英]Ldap filter for multiple Ou's Powershell

Hello guys still pretty new to Powershell and never worked with Ldap -filter before so i have a question.大家好,大家对 Powershell 还是很陌生,之前从未使用过 Ldap -filter 所以我有一个问题。 Is it possible to get AD-User's out of mulitple Ou's with one Ldap filter?是否可以使用一个 Ldap 过滤器从多个 Ou 中获取 AD 用户?

OU=D5,OU=Standard,OU=User,OU=1,DC=test,DC=for-me,DC=nl
OU=D3,OU=Standard,OU=User,OU=1,DC=test,DC=for-me,DC=nl
OU=G2,OU=General,OU=User,OU=1,DC=test,DC=for-me,DC=nl
OU=C6,OU=Expired,OU=User,OU=1,DC=test,DC=for-me,DC=nl

Im sorry i have not even a Code example but nothing i've tried came near to what i want.对不起,我什至没有代码示例,但我尝试过的任何东西都没有接近我想要的。 Im open for tipps, hints, ideas etc. Thanks already.我愿意接受小费、提示、想法等。已经谢谢了。

You cannot make the OU part of the LDAP filter.您不能使 OU 成为 LDAP 过滤器的一部分。 But you can make an OU the base of your search and issue multiple searches.但是您可以将 OU 作为搜索的基础并发出多个搜索。

# an array of OUs, this could also be achieved with e.g. $OUs = Get-Content 'some_file.txt'
$OUs = @(
    "OU=D5,OU=Standard,OU=User,OU=1,DC=test,DC=for-me,DC=nl"
    "OU=D3,OU=Standard,OU=User,OU=1,DC=test,DC=for-me,DC=nl"
    "OU=G2,OU=General,OU=User,OU=1,DC=test,DC=for-me,DC=nl"
    "OU=C6,OU=Expired,OU=User,OU=1,DC=test,DC=for-me,DC=nl"
)

foreach ($ou in $OUs) {
    Get-ADUser -SearchBase $ou
}

Well it is not an LDAP Query and might be suspicious in a very large environment, but normally I suggest use the filter options of Powershell like below:好吧,它不是 LDAP 查询,在非常大的环境中可能会很可疑,但通常我建议使用 Powershell 的过滤器选项,如下所示:

Get-ADUser -Filter  * | Where-Object { $_.DistinguishedName.split(",",2)[1] -in 
    "OU=D5,OU=Standard,OU=User,OU=1,DC=test,DC=for-me,DC=nl",
    "OU=D3,OU=Standard,OU=User,OU=1,DC=test,DC=for-me,DC=nl",
    "OU=G2,OU=General,OU=User,OU=1,DC=test,DC=for-me,DC=nl",
    "OU=C6,OU=Expired,OU=User,OU=1,DC=test,DC=for-me,DC=nl"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM