Parity123
asked on
Powershell script looking for user count
Hello,
I am running the following powershell script and it is giving an error "Invalid enumeration context", in get-aduser. I have close to 800,000 user objects in the domain.
$AllUsers = get-aduser -filter *
$TotalUserCount = $AllUsers.count
Could you please suggest how to get this to work. This script worked in other smaller domains.
Thanks
I am running the following powershell script and it is giving an error "Invalid enumeration context", in get-aduser. I have close to 800,000 user objects in the domain.
$AllUsers = get-aduser -filter *
$TotalUserCount = $AllUsers.count
Could you please suggest how to get this to work. This script worked in other smaller domains.
Thanks
ASKER
I tested this. It looks like it is running for a while and then terminates with error cannot contact server, unless the connection times out after a while.
Are there any other options
Are there any other options
ASKER
I still get the same error - invalid enumeration context
What David Johnson post earlier is very similar to the examples in the offing like but they use brackets
http://support.risualblogs.com/blog/2012/07/24/view-number-of-user-accounts-in-ad-via-ad-powershell/
http://support.risualblogs.com/blog/2012/07/24/view-number-of-user-accounts-in-ad-via-ad-powershell/
that means that it is timing out .. the reason for the limit was to not overload your DC. use a filter i.e. run it 36 times
get-aduser -Filter 'samaccountname -like "a*" '
$firstletter="abcdefghijklmnopqrstuvwxyz0123456789"
$usercount = 0
$lettercount = $firstletter.Length
for($i=0; $i -le $lettercount; $i++){
$filter = $FirstLetter[$i] + "*"
$users = get-aduser -Filter 'samaccountname -like $filter'
if ($users.Count -ne $null){
$usercount += $users.Count
}
}
$usercount
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I tried a few things
get-aduser -resultsetsize $null to return all
Open in new window
Quest Tools get-qaduser -sizelimit 0 is the equivalent