I must be doing something silly but I'm damned if I can see what. According my Googling this Powershell script should list the members of the Domain Users group:
$root=([ADSI]"").distinguishedName
$group = [ADSI] ("LDAP://cn=Domain Users,cn=Users," + $root)
Write-Host $group.distinguishedName
Write-Host "Members:"
foreach ($member in $group.member)
{
$member
}
But when I run it I just get the output:
CN=Domain Users,CN=Users,DC=mydomain,DC=local
Members:
So it's finding the group OK but not listing the members. I've tried this on Server 2003 and Server 2008 and I'm out of ideas for where my obvious mistake is. Please help ...
JR
I've never done this in PowerShell, but I have seen the same problem in VBScript.
If Domain Users is a user's Primary Group, then that user will not show up as a member. Try changing your Primary Group to something else and then run your script again.
Hmm. It's working for me. Are you running this as a script or typing it interactively?
If after hitting enter (or paste) in an interactive session you get a
>>
prompt, then hit enter again and see if you get your results.Assuming, of course, that there actually are users in your group ;)
Odd, it seems that the Domain users group does not have the member properties. If i query another group in my domain I get the properties.
I took a peek at the group in ADSI Edit, and the member property is empty.
I would go into ADSI Edit and check the member property of the domain admins group and see if there are any entries there.
As to why they aren't there and how the group is getting it's membership, I'm not quite sure and would be curious to the answer to that myself.
Is this Powershell 1.0 or 2.0? I'm running it on Powershell 2.0 and I also got blank output. However, after doing a "$group | get-member", I see there is a property called "MemberOf" (nothing listed for just "member").
In this case, if you change the last line to:
After this change, I get what looks like the desired output.