我有一个recursion列出组成员的脚本。 问题是有超过5K,所以我不能使用Get-ADGroupMember,我也只需要获得启用用户。 UAC,尽pipe微软的文档,不只显示启用用户。 我有这个,但不过滤启用。
Function Get-MyLargeGroup { [cmdletbinding()] Param( [Parameter(Position=0,ValueFromPipeline,ValueFromPipelineByPropertyName)] [ValidateNotNullorEmpty()] [string]$Name) Begin { Write-Verbose "Starting $($MyInvocation.MyCommand)" } #begin Process { Write-Verbose "Retrieving members from $Name" $mygroup = Get-ADGroup -Identity $Name -Properties Members foreach ($member in $mygroup.members) { $object = $member | Get-ADObject -Properties samaccountname,enabled if ($object.ObjectClass -eq 'Group') { Write-Verbose "Found nested group $($object.distinguishedname)" #recursively run this command for the nested group & $MyInvocation.MyCommand -name $object.Name } else { Select-Object -InputObject $object -property ObjectClass,Name,SamAccountname,DistinguishedName,enabled } } #foreach } #process End { Write-Verbose "Ending $($MyInvocation.MyCommand)" } #end } #end function
除非Get-ADUser有一些非常古老的限制,我不知道,使用它可能会返回超过5k用户的查询应该没有问题。 我刚刚从运行PowerShell 4的2008 R2框中进行了testing,我的Get-ADUser查询几乎返回了7k个用户,只有-Filter *和-SearchBase参数。 我也不清楚为什么你认为UAC与能够筛选已启用的用户有任何关系。
无论如何,你并不需要为此任务recursion的脚本。 您可以使用LDAP筛选器,它将返回名为LDAP_MATCHING_RULE_IN_CHAIN的组成员的完整嵌套列表。
# first, get the DN of the group $groupDN = (Get-ADGroup $Name).DistinguishedName # now use it to get the nested members Get-ADUser -LDAPFilter "(memberOf:1.2.840.113556.1.4.1941:=$groupDN)" -Property SamAccountname,Enabled | select ObjectClass,Name,SamAccountname,DistinguishedName,enabled # alternatively, you can filter out the disabled users in the same query Get-ADUser -LDAPFilter "(&(memberOf:1.2.840.113556.1.4.1941:=$groupDN)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))" -Property SamAccountname,Enabled | select ObjectClass,Name,SamAccountname,DistinguishedName,enabled
您的脚本不能为启用用户工作的原因是因为“已启用”不是Get-ADObject cmdlet的有效属性。 它适用于Get-ADUser和Get-ADComputer。 使用Get-ADObject,您需要解码userAccountControl属性的值 。
Get-ADGroupMember上的5,000条logging限制是由域控制器上运行的AD Web服务设置的限制。 您可以修改ADWS参数以允许返回更大的结果。
您可以返回超过5,000个组成员,而无需使用以下PowerShell修改ADWS参数:
(Get-ADGroup -Identity "SomeGroupName" -Properties Members).members
您需要使用Get-ADObject cmdlet循环查看其他对象信息。