Always getting 1500 member of distribution list using PowerShell

僤鯓⒐⒋嵵緔 提交于 2020-01-11 06:15:11

问题


I would like to get all members (mail address) of a certain distribution list. Currently I just recieve the first 1500 members. My Script looks like that:

$group = [ADSI]"LDAP://CN=distListOne,OU=Groups,DC=XYZ,DC=XYZ"
$group.member.count ##Always 1500 
foreach($member in $group.member)
{
    $filter = "LDAP://"+$member
    $user = [ADSI]$filter
    $user.properties.mail | out-file "C:\distrUser.txt" -append 
}

I know that there are more than 1500 users in the distribution list. I need anyhow to extend the maximum recieved groupmembers.


回答1:


You need to change your code to use a DirectorySearcher approach, and check out the PageSize property of the DirectorySearcher

Setting that value to something (instead of leaving it 0) will start paged searching to allow AD to return more than 1500 members. It is recommended to set the PageSize to a sensible value like 500 or 1000 - if you set it too high (higher than the system limit of 1500), it will be ignored and won't work!

See some other blog posts on how to tackle this problem:

  • Get more than 1500 members from an Active Directory group

  • List Members of Large Group




回答2:


When retrieving a large attribute you need to ask for the values in it in batches. This is often called "ranged retrieval" in directory speak. Nearly every well behaving MSFT LDAP API supports this, including ADSI... http://msdn.microsoft.com/en-us/library/windows/desktop/ms676302(v=vs.85).aspx




回答3:


This will work quite nicely, requires the active directory module

(Get-ADGroup $Group -Properties members).members



来源:https://stackoverflow.com/questions/11984305/always-getting-1500-member-of-distribution-list-using-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!