I would like to get a count of users in a Distribution group in AD.
I have used the following command to get an export to xls, csv, txt but the columns aren't arranged in a way to allow me to check out how many users there are.
We seem to have a problematic DL. Powershell is giving me a count of members, I just want to verify its correct by checking with another LDAP querier! :)
Chris Dent
Ah ha :-D
DSQuery?
DSQuery group -Name "The Group" | DSGet group -members -expand
So this will give me just the count or will it export it out somewhere?
Chris Dent
The DSQuery / DSGet command above will just drop a few lines to the console. Redirecting it to a text file will give you an easy place to count (line count if you do View / Status Bar).
DSQuery group -Name "The Group" | DSGet group -members -expand > GroupMembers.txt
There is one other thing that might be worth mentioning.
Universal Distribution Groups will not list all of their membership when you query the a standard Domain Controller. Instead you have to direct the query at a Global Catalog.
Might not be your issue, but I'm off home now so I figured it was worth mentioning ;)
In PowerShell that's:
(Get-QADGroupMember "The Group" -UseGlobalCatalog).Count
It's a bit more difficult with DSQuery, but something like this would do it:
Where ForestRoot is actually an option in DSQuery rather than something you have to change. However, it does need the full DN of the group or it won't find anything.
I did have one more thought while I was on the train...
If you have a large group and you're trying to get the membership you might be bumping into a few more of the more obscure issues. How big is the group? Where big is typically more than 1500 members.
Chris
kam_uk
ASKER
Hi
The group is about 5000 odd?
Chris Dent
How inaccurate is the count you're getting?
I'll make a few thousand users on my domain here and see if I can see any discrepancies.
If a little slowly... the trouble with broadly scoped searches on large domains...
DSQuery also works as follows:
(dsquery group -name "TheGroup" | dsget group -members -expand).Count
Although you have to do a -1 there because it's a bit of a rough way, relying on an implicit conversion of the returned lines to an array.
In summary, we need Dimitry to fix Quest's components. MS's cmdlets aren't going to be around for quite a long time and any of the simpler methods (vbscript, System.DirectoryServices) are flawed for large groups except using the same LDAP search as above.
You are correct. Legacy groups are groups with some or all members that are not LVR'd. Once the functionality level is upped only new members are LVR'd.
I have seen this cause issues with scripts... just something to look at.
Chris Dent
Hmm I did have a look at that last night when you posted.
The group I'd created, and all associated users, were created in a 2008 Native Mode domain. I ran ADFind against it with the flag in that for reporting on those and it seemed quite happy with the group.
Might have another go tonight, it's possible my Vista installation was unhappy with the Quest tools :)
Chris
BSonPosh
understand... this can only act qwerky if you were in a domain in pre 2003 mode
Your mentioning it made me read up on the limits a bit (which was interesting) so I can appreciate the point and why it might be pertinent here :)
It might be worth testing that for the group in the original question anyway considering it's size.
Chris
kam_uk
ASKER
Many thanks - really appreciate your help ;)
vigge79
I require some assistance to convert legacy groups to LVR groups. I am using a powershell command but when i run this script a message displays
"dsmod failed:"group name": directory object not found
but when i execute the simple command within CMD the group converts without issues
Hey dude :)
Going to push PowerShell on you again :)
(Get-QADGroupMember "The Group").Count
Or just members if you do:
Get-QADGroupMember "The Group"
Chris