I want to retrieve, in a CSV file, all AD users. But every time I run my script the CSV file has a different amount of users.
I know there are up to 4000 users... but retrieved sometimes 500 to 600 results.
I noticed in my CSV file, at the last row something like
"Person Name", "person.name@email.com","person.name","CN=somewhere,OU=USERS,OU=THERE,OU=HERE,OU=SOMEPLACE,OU=ORG,DC= (here is the part where it breaks)
I noticed, always in the final row, the result is break. Is there a limit to my CSV file?
I can't figure out, what is happenning.
$path = ".\Users.csv"
$root = [adsi]''
$searcher = New-Object System.DirectoryServices.DirectorySearcher($root)
$searcher.Filter = "(&(objectClass=user))"
$searcher.PageSize = 5000 #iknow the max is 1000, but when i do it, and count my result, its show up 4000+
$searcher.SizeLimit = 5000
$cols = "cn", "mail", "samaccountname", "distinguishedname"
foreach ($i in $cols) {$searcher.PropertiesToLoad.Add($i)}
$users = $searcher.FindAll() |
Select-Object @{e={$_.properties.cn};n='DisplayName'},
@{e={$_.properties.mail};n='Email'},
@{e={$_.properties.samaccountname};n='sAMAccountName'},
@{e={$_.properties.distinguishedname};n='distinguishedname'}
$users | Export-Csv $path -Delimiter ";" -Encoding Default #now delimiting using ";" to do have problems with my string with commas