Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm running Windows 7 Professional.

I know how to get a list of all the users in a group:

$ou="User Groups"
$userADName="RRAS VPN SSL"
$user = [adsi] $userADPath

I tried iterating over that list, creating an [adsi] object for each:

$ou="User Groups"
$userADName="RRAS VPN SSL"
$user = [adsi] $userADPath
$user.Member| ForEach-Object {[adsi] ("ldap://" + $_)}

I was thinking of looping over the list of objects and fetching the email address and full name, then running some commands using that information. Instead, this produces the error:

The following exception occurred while retrieving member "PSComputerName": "Unknown error (0x80005000)"
    + CategoryInfo          : NotSpecified: (:) [format-default], ExtendedTypeSystemException
    + FullyQualifiedErrorId : CatchFromBaseGetMember,Microsoft.PowerShell.Commands.FormatDefaultCommand

How can I iterate over the list of users in a group, processing the email address and full name for each user?

share|improve this question
up vote 1 down vote accepted

You get this error because the LDAP path that you are sending to the loop is not right. You are pipeing $user.Member to the ForEach-Object, it sends all users and not one bye one.

So you are sending something like:

ldap://,CN=Users,DC=prod,DC=root CN=User2,CN=Users,DC=prod,DC=root

I created this script based on yours, it do what you need: interate over the members of a group. Do what you want with the object $useradsi in the loop.

$ou="User Groups"
$userADName="RRAS VPN SSL"
$objADSI = [adsi]””
$domain = $objADSI.distinguishedname
$user = [adsi] $userADPath

foreach($child in $user.member) {
$useradsi = [adsi] "LDAP://$child"
share|improve this answer
I'll post my final script once it's final, but this answer has enabled me to loop through all the users and then mess each one up. – John Saunders Nov 1 '11 at 1:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.