【发布时间】:2021-04-25 19:18:18
【问题描述】:
我已经编写了以下内容,并且它可以工作(基于 Check if the user is a member of a list of AD groups),但是它需要 难以置信 很长时间才能运行 - 我假设这是因为它检索了整个组对于每个用户。我已经尝试在开始时将 $members... 行移出函数以检索一次组列表,但似乎没有任何区别。
有没有更有效的方式返回这些信息?
samaccountname enabled InDenyGroup
-------------- ------- -----------
admin-abc True yes
admin-def True yes
在此示例中,帐户名称过滤器为“king”,因为检查帐户是否在组中。
Get-ADUser -Filter "(SamAccountName -like 'admin*') -and (enabled -eq 'true')" |
ft -AutoSize samaccountname,enabled,@{Name='InBlockGroup'; Expression={InDenyGrp($_.samaccountname)}}
Function InDenyGrp([string]$UserID) {
$members = Get-ADGroupMember -Identity "myBlockGroup" | Select -ExpandProperty SamAccountName
If ($members -contains $UserID) {
Return "yes"
} Else {
Return "not in group"
}
}
谢谢。
【问题讨论】:
标签: powershell active-directory