We help IT Professionals succeed at work.

Exchange 2007: DSGET and DSQUERY returning erro when listing members of distribution group

Lokton23
Lokton23 asked
on
Need to pull member's names and corresponding email addresses from distribution lists.  
Distribution groups are Universal.
There are domain users and contacts listed in the each groups.

Previously, was able to use the following DSGET and DSQUERY command:

dsquery group -name "GROUP NAME"|dsget user -samid -email >c:\file.txt

Now I receive the following error when I run this on multiple distribution groups:

dsget failed:CN=USERNAME,OU=WHATEVER,OU=WHENEVER,DC=ALWAYS,DC=corp:
The object class of the target does not match the one specified on the command line.
type dsget /? for help.[PS] C:\Windows\system32>:


Any help would be appreciated.



Comment
Watch Question

Chris DentPowerShell Developer
Top Expert 2010

Commented:

Hey there,

You would be better with this:


Get-DistributionGroupMember "Group Name" | Export-Csv "File.csv"


It'll take care of object types for you.

Chris

Author

Commented:
Chris thx for the reply.

Lists the group members.  What we need is Group Members and their email address.

Anyway to pull that using your method?

Also, where does |Export-Csv "File.csv" get saved to?
PowerShell Developer
Top Expert 2010
Commented:

Certainly :) Do you need more than this?

Get-DistributionGroupMember "Group Name" | Select-Object Name, PrimarySmtpAddress | Export-Csv "File.csv"

And file.csv is saved in your current directly, but you can supply a full path (e.g. c:\somewhere\file.csv).

Chris

Author

Commented:
TY Mr. Dent apprciate the assist.
Chris DentPowerShell Developer
Top Expert 2010

Commented:

You're welcome :)

Chris

Author

Commented:
Works like a champ.  

Author

Commented:
Works
Chris DentPowerShell Developer
Top Expert 2010

Commented:

Hey :)

It looks like the close option got a bit confused, I'm only objecting on those grounds.

Has it managed to hide the Accept as Solution button again?

Cheers,

Chris
Chris DentPowerShell Developer
Top Expert 2010

Commented:
I recommend accept http:#32991533.

Cheers,

Chris