.NET Framework - Search.All in AD (LDAP) found exactly 1000 - is this a built in limit?

Asked By Bruce Sanderson
29-Aug-08 05:08 PM
I ran a script to list all computers in an Active Directory OU (or a child
OU) with their last password changed date.  This seems to work OK, but I got
exactly 1000 computer accounts listed.  I'm, pretty sure there are more than
1000 computer accounts, becuase some computer accounts are in OUs that don't
appear in the list.

Is there a built-in limit to how many items will be returned by an LDAP
query or that can be put into a Power Shell variable and if so, can this be
changed or is there some way to get the rest of the computer accouts?

Here's the script I'm using (I've changed the OU names):

$root=[ADSI]"LDAP://OU=Workstation
Computers,OU=Base,OU=mine,OU=ours,DC=domain,DC=local"
$search=[System.DirectoryServices.DirectorySearcher]$root
$Search.Filter="(&(objectcategory=computer))"
$result=$search.FindAll()
.\computers.txt

foreach ($Computer in $result)
{
$parts = $Computer.properties.distinguishedname -split ","
Foreach ($namepart in $parts)
{
$TypeName = $namepart -split "="
switch ($TypeName[0])
{
{
$OU = ""}
If (($TypeName[1] -eq "Base") -or ($TypeName[1] -eq
{Continue}
Else
{$OU=$TypeName[1], $OU -join "\"
}
}
}
$ComputerName = $Computer.properties.cn | out-string -stream
$pwdlastset =
[datetime]::FromFileTime($Computer.properties.item('pwdlastset')[0])
If ($pwdlastset -eq "31-Dec-1600 4:00:00 PM")
{$pwdlastset ="Never"}
$LastLogon =
[datetime]::FromFileTime($Computer.properties.item('lastLogonTimestamp')[0])
If ($LastLogon -eq "31-Dec-1600 4:00:00 PM")
{$LastLogon ="Never"}

}
-join ($ComputerName, "`t", $OU, "`t", $pwdlastset, "`t", $LastLogon) >>
.\computers.txt
}



--
Bruce Sanderson
http://members.shaw.ca/bsanders/
It's perfectly useless to know the right answer to the wrong question.
System.DirectoryServices.DirectorySearcher
(1)
Active Directory
(1)
Search.PageSize
(1)
Computer.properties.distinguishedname
(1)
Search.Filter
(1)
FromFileTime
(1)
Search.FindAll
(1)
LastLogon
(1)
  alexandair replied...
31-Aug-08 10:37 PM
On Aug 29, 11:08=A0pm, "Bruce Sanderson" <bsand...@newsgroups.nospam>
d
I got
than
n't
be
Name)
1] -eq
$OU)
ream
0]=AD)
gon) >>

You need $Search.PageSize =3D 1000

By default, the search returns a maximum of 1000 results to prevent
load on the domain controller executing the search. By setting
PageSize to anything, you in effect disable the limitation altogether.
You may ask why would you set PageSize to 1000, and here is the answer
taken from Tobias Weltner's Mastering PowerShell in your Lunch Break
(Day 6: ADSI Connecting to Domains/Computers and Binding to Objects)
(http://powershelllive.com/blogs/lunch/archive/2007/04/04/day-6-adsi-
connecting-to-domains-computers-and-binding-to-objects.aspx):

results in one chunk. If it gets larger than 1000 objects, the
internal limitation kicks in and cancels the search. You get
incomplete results.

If you do set a PageSize, then you get back the results in separate
chunks, each with the size defined in PageSize. So, as long as your
PageSize is smaller than or equal to 1000, the chunks will not trigger
the limitation, and you get all results. You can try and set PageSize
=3D 1. You still get all results. The results now come in chunks of
exactly one entry which slows down the search. The best way therefore
is to set PageSize to the maximum allowed size of 1000. This limit is
set in your AD schema and may have been changed to another value."

-aleksandar
http://powershellers.blogspot.com
  Bruce Sanderson replied...
02-Sep-08 02:03 PM
Thank you very much, both for the solution and the explanation!

That fixed the problem - I now get all 2,331 computer accounts.

--
Bruce Sanderson
http://members.shaw.ca/bsanders/
It's perfectly useless to know the right answer to the wrong question.


On Aug 29, 11:08 pm, "Bruce Sanderson" <bsand...@newsgroups.nospam>

You need $Search.PageSize = 1000

By default, the search returns a maximum of 1000 results to prevent
load on the domain controller executing the search. By setting
PageSize to anything, you in effect disable the limitation altogether.
You may ask why would you set PageSize to 1000, and here is the answer
taken from Tobias Weltner's Mastering PowerShell in your Lunch Break
(Day 6: ADSI Connecting to Domains/Computers and Binding to Objects)
(http://powershelllive.com/blogs/lunch/archive/2007/04/04/day-6-adsi-
connecting-to-domains-computers-and-binding-to-objects.aspx):

results in one chunk. If it gets larger than 1000 objects, the
internal limitation kicks in and cancels the search. You get
incomplete results.

If you do set a PageSize, then you get back the results in separate
chunks, each with the size defined in PageSize. So, as long as your
PageSize is smaller than or equal to 1000, the chunks will not trigger
the limitation, and you get all results. You can try and set PageSize
= 1. You still get all results. The results now come in chunks of
exactly one entry which slows down the search. The best way therefore
is to set PageSize to the maximum allowed size of 1000. This limit is
set in your AD schema and may have been changed to another value."

-aleksandar
http://powershellers.blogspot.com
Create New Account
help
How to Verify Users are Disabled in Active Directory .NET Framework I have a list of several users in an excel spreadsheet. Is it possible to retrieve the users in the excel spreadsheet and parse active directory to ensure that those users are disabled? Powershell Discussions System.DirectoryServices.DirectorySearcher (1) Active Directory (1) Excel (1) SAMAccountName (1) QADUser (1) User.UserAccountControl (1) User.GetDirectoryEntry (1) User
dass Password lesen! System.DirectoryServices.DirectoryEntry entry = new System.DirectoryServices.DirectoryEntry("LDAP: / / DM", "Administrator", "Administratorpw"); System.DirectoryServices.DirectorySearcher search = new System.DirectoryServices.DirectorySearcher(entry); search.Filter = "(&(objectClass = user)" + foreach (System.DirectoryServices.SearchResult result in search.FindAll()) { ??? } Ist dies überhaupt möglich und wenn ja, wie? mfG Hendrik C# - German Discussions SecureStringToBSTR (1) System.DirectoryServices.DirectorySearcher (1) PtrToStringBSTR (1) System.DirectoryServices.DirectoryEntry (1) System.DirectoryServices.SearchResult (1) CredUICmdLinePromptForCredentials (1) CredUIPromptForWindowsCredentials
Afficher attribut caché Active Directory .NET Framework Bonjour, J'ai un problème avec le script suivant $ldapQuery = "(&(objectclass = user))" $de = [ADSI]"LDAP: / / *.*.*.* / ou = *, OU = *, dc = *, dc = *" $ads = new-object system.directoryservices.directorysearcher -argumentlist $de, $ldapQuery $complist = $ads.findall() foreach ($i in $complist) { $i.properties.employeeID $i.properties ou = *, OU = *, dc = *dc = *" $user.get("employeeID") Pouvez-vous m'aider? Merci Scripting - French Discussions Active Directory (1) Windows Server (1) User.Properties.ProtertyNames (1) UserAccountControl (1) DirectorySearcher (1) EmployeeID (1) Directoryentry.Properties (1) System.directoryservices.directorysearcher (1) Bonjour, Un objet Ordinateur Active Directory est également membre de la classe
Convert Active Directory IADSLargeInteger .NET Framework I thought this was going to be easy after finally getting my User pwdlastset values - I am now unable to convert them - I have tried using the System.DirectoryServices.DirectorySearcher method described in the following url http: / / bsonposh.com / modules / wordpress / ?p = 30 but am following with no success: http: / / weblogs.asp.net / adweigert / archive / 2007 / 03 / 23 / powershell-convert-active-directory-iadslargeinteger-to-system-int64.aspx - - jobbsy@ Powershell Discussions System.DirectoryServices.DirectorySearcher (1) System.Reflection.BindingFlags (1) Active Directory (1) ConvertADSLargeInteger (1) IADSLargeInteger (1) System
Get AD User Names .NET Framework Does anyone know the command to query active directory for all user names? I simply want a list of all users with the output only by samaccountname. Thanks, Rey Powershell Discussions System.DirectoryServices.DirectorySearcher (1) QADUser (1) FindAll (1) ForEach (1) Poshoholic (1) SizeLimit (1) Siddaway (1) Rey (1 QADUser -sizeLimit 0 | % {$_.samaccountname} - - Kirk Munro Poshoholic http: / / poshoholic.com Two options (new-Object system.DirectoryServices.DirectorySearcher([ADSI]"", "(objectclass = user)")).FindAll() or if you dont mind install the FREE quest tools get