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.