how to comebine get-distributiongroupmember and get-aduser to work in PowerShell?

I can get the distribution group members. I need to take each one of those members and run them through get-aduser so that I can get the ad properties for each member. I have a script written that gets the dist group then the dist group member, I just need to take that member to get-aduser and send the properties to the same file that I am sending the dist group members to. The problem is after I user the get-distrobutiongroupmember cmdlet, I can't get the identity of that member into the get-aduser cmdlet. - Thanks in Advance - Jerry Shean
Jerry SheanNetwork/Systems AdministratorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nadav SolomonCommented:
You can pass the distinguished name to get-aduser (the same way i used it for the adsi user object $_.distinguishedname), the thing is that you need to import the active directory module too, so why not work with ADSI?
here is an example:

Get-DistributionGroupMember groupName| %{
    $user = [ADSI]"LDAP://$($_.distinguishedname)"
    $user.samaccountname
    $user.displayName
}

Open in new window

0
Jerry SheanNetwork/Systems AdministratorAuthor Commented:
I will send a code snippetdistlist5.txtdistlist5.txtdistlist5.txtdistlist5.txt to show my approach, (very, very wrong) to this problem. I know that what I want to do isn't that difficult, but I am a PowerShell newbidistlist5.txte. I have attached the ps1 file. - Thanks
0
Nadav SolomonCommented:
I think this one is a bit more organized, add the attributes you want in line 8 or feel free to change it any way you want to.
I don't know why you wanted to sort them in line 4 but i left it as it was.
Enjoy :D

$file = "C:\users\jerrymshean\desktop\powershell\outputDGmembers4.txt"

Add-Content -path $file -value ""
get-distributiongroup -ResultSize unlimited | Sort -Property DisplayName | %{
    Add-Content -path $file -value "Group Name: $($_.displayname)"
     Get-DistributionGroupMember $_ -resultsize unlimited | %{
        $user = [ADSI]"LDAP://$($_.distinguishedname)"
        Add-Content -path $file -value "User Name: $($user.samaccountname), userPrincipalName: $($user.userPrincipalName)"
    }
}

Open in new window

0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Jerry SheanNetwork/Systems AdministratorAuthor Commented:
I am very grateful for your help. However, I copied the file and ran it unchanged. Here is the error that I get:

Cannot process argument transformation on parameter 'Identity'. Cannot convert the "2020vision" value of type
"Deserialized.Microsoft.Exchange.Data.Directory.Management.DistributionGroup" to type
"Microsoft.Exchange.Configuration.Tasks.DistributionGroupMemberIdParameter".
    + CategoryInfo          : InvalidData: (:) [Get-DistributionGroupMember], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-DistributionGroupMember
    + PSComputerName        : uchub01
0
Nadav SolomonCommented:
working great for me, can you provide a screenshot? are you running this in Exchange powershell?
0
Jerry SheanNetwork/Systems AdministratorAuthor Commented:
here is a screenshot. I don't know how well it will come out. Yes I am attached to an exchange server.screen.rtf
0
Jerry SheanNetwork/Systems AdministratorAuthor Commented:
Could you look at line 6? It doesn't look right somehow.
0
Nadav SolomonCommented:
Please run it under "Exchange Management Shell" and not ISE.
If you do run it under ISE you need to add the snap-in of Exchange 2010.
let me know if this helped
0
Jerry SheanNetwork/Systems AdministratorAuthor Commented:
I have added the exchange snapin and reran your provided code again. Below you will find a sample of the errors returned and created file content. - Thank you again for your help.

Sample Errors:

Cannot process argument transformation on parameter 'Identity'. Cannot convert the
"Unaddressed Messages - UNITY" value of type
"Deserialized.Microsoft.Exchange.Data.Directory.Management.DistributionGroup" to type
"Microsoft.Exchange.Configuration.Tasks.DistributionGroupMemberIdParameter".
    + CategoryInfo          : InvalidData: (:) [Get-DistributionGroupMember], ParameterBin
   din...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-DistributionGroupMe
   mber
    + PSComputerName        : uchub01.ucwv.edu
 
Cannot process argument transformation on parameter 'Identity'. Cannot convert the
"Unaddressed Messages - UNITY" value of type
"Deserialized.Microsoft.Exchange.Data.Directory.Management.DistributionGroup" to type
"Microsoft.Exchange.Configuration.Tasks.DistributionGroupMemberIdParameter".
    + CategoryInfo          : InvalidData: (:) [Get-DistributionGroupMember], ParameterBin
   din...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-DistributionGroupMe
   mber
    + PSComputerName        : uchub01.ucwv.edu
 
Cannot process argument transformation on parameter 'Identity'. Cannot convert the
"Unitytest" value of type
"Deserialized.Microsoft.Exchange.Data.Directory.Management.DistributionGroup" to type
"Microsoft.Exchange.Configuration.Tasks.DistributionGroupMemberIdParameter".
    + CategoryInfo          : InvalidData: (:) [Get-DistributionGroupMember], ParameterBin
   din...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-DistributionGroupMe
   mber
    + PSComputerName        : uchub01.ucwv.edu
 
Cannot process argument transformation on parameter 'Identity'. Cannot convert the
"Weather Dist List" value of type
"Deserialized.Microsoft.Exchange.Data.Directory.Management.DistributionGroup" to type
"Microsoft.Exchange.Configuration.Tasks.DistributionGroupMemberIdParameter".
    + CategoryInfo          : InvalidData: (:) [Get-DistributionGroupMember], ParameterBin
   din...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-DistributionGroupMe
   mber
    + PSComputerName        : uchub01.ucwv.edu
 
Sample data in created file:

Group Name: 2020vision
Group Name: AAPS
Group Name: academicprograms
Group Name: ACCP
Group Name: Adjuncts
Group Name: Admin
Group Name: All Subscribers - UNITY
Group Name: All Subscribers - UNITY
Group Name: AllBeckley
Group Name: alumniforward
Group Name: APhA-ASP
Group Name: ASCP
0
Nadav SolomonCommented:
Try this way:
$file = "C:\users\jerrymshean\desktop\powershell\outputDGmembers4.txt"

Add-Content -path $file -value ""
get-distributiongroup -ResultSize unlimited | Sort -Property DisplayName | %{
    Add-Content -path $file -value "Group Name: $($_.displayname)"
     Get-DistributionGroupMember -Identity $_.identity -resultsize unlimited | %{
        $user = [ADSI]"LDAP://$($_.distinguishedname)"
        Add-Content -path $file -value "User Name: $($user.samaccountname), userPrincipalName: $($user.userPrincipalName)"
    }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jerry SheanNetwork/Systems AdministratorAuthor Commented:
Thank you so much! This seems to work just fine. I hope that I can "Pass it forward", to help someone else in the future. If there is any error that pops up, I will contact you. As far as I can tell there shouldn't be any. Once again thank you very much.- Jerry Shean
0
Nadav SolomonCommented:
Glad I could help, thanks for the feedback.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.