Asking for PowerShell script to export list of Distribution Groups with members and email addresses in an OU to a .csv file

I want to get a .csv file listing the members (and email addresses) of all the distribution groups in one OU in Active Directory. I have found code that is supposed to do this but when I run it in the PowerShell command window I get this error:

Get-DistributionGroup : The term 'Get-DistributionGroup' is not recognized as the name of a cmdlet, function, script file, or operable program.

The forum where I got that is from 2012 so has that command been deprecated?

Bottom line is, can someone provide this script?
donanderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

spmtCommented:
hello ,

normally this command should work on exchange server

you can use this to find command in powershell

Get-Help *distrib*


on your AD you can try this

Import-Module ActiveDirectory

Get-ADGroup -Filter {GroupCategory -eq "Distribution"} -Properties Members

Thanks and Regards,
0
donanderAuthor Commented:
When I run it I get the following result which I don't think is what I need. Strange.

PS H:\> Get-Help *distrib*

NAME
    Enable-BCDistributed

SYNTAX
    Enable-BCDistributed


ALIASES
    None


REMARKS
    None
0
donanderAuthor Commented:
In the meantime, I have received the names of the Distribution Groups so I tried this:

Import-Module ActiveDirectory
Get-DistributionGroupMember -identity "!Dept_MyDepartment_Faculty" | export-csv -NoTypeInformation -path.\Dept_MyDepartment_Faculty.csv

but I still get the same error about the command not being recognized.
0
Challenges in Government Cyber Security

Has cyber security been a challenge in your government organization? Are you looking to improve your government's network security? Learn more about how to improve your government organization's security by viewing our on-demand webinar!

donanderAuthor Commented:
I ran

PS H:\> Get-Help Get-

and got hundreds of results. I copied them into MS Word, sorted them alphabetically and searched for

get-dis and there are only the 3 shown below with the result before and after so it appears that my PowerShell doesn't know about Get-Distribution...

Get-DhcpServerVersion             Function  DhcpServer                ...
Get-Disk                          Function  Storage                   ...
Get-DiskImage                     Function  Storage                   ...
Get-DiskStorageNodeView           Function  Storage                   ...
Get-DnsClient                     Function  DnsClient                 ...
0
spmtCommented:
Hello,

if you can't find the command in powershell, you can't use it

try this

Import-Module ActiveDirectory

Get-ADGroup -Properties Members -Filter {identity -notlike "Dept_MyDepartment_Faculty"}


command Get-ADGroup -Properties Members give you the same output that  Get-DistributionGroupMember command will do.

you are not on exchange server so i don't think you will find the command  Get-DistributionGroupMember
0
Jacob DurhamIT Support Analyst II (Lead Infrastructure Engineer)Commented:
You need to either run this on the DC or install the Active Directory Remote Server Administration Tools to your workstation.
0
FOXActive Directory/Exchange EngineerCommented:
Donander,
You have stated that you have the names of the distribution groups.  So let's take it from there
Open Exchange Management Shell
1. On the machine where you have the shell open Create a folder on your c:\drive named Temp
2.  I want you to list all the groups one underneath each other with a header of Name(example below)
Name
GroupA
GroupB
DistrGroupC

Whether the file is made in notepad or excel please name the file Grps.csv and save it in the Temp folder on your c: drive
So your file should be c:\temp\Grps.csv

Now Create a folder inside of Temp named DLs
example c:\Temp\DLs     (inside Dls is where all your new .csv files will drop with the info you need after you run the below command)

Now for the magic:

Import-csv 'c:\temp\grps.csv' | %{ $name = $_.Name; Get-DistributionGroupMember $_.Name | Select Name,PrimarySmtpAddress | Sort Name | Export-csv "c:\temp\DLs\$name.csv" -notypeinformation }
0
donanderAuthor Commented:
Sorry, I didn't see these comments until just now.

Regarding comment from spmt:
If I execute
Get-ADGroup -Properties Members -Filter {identity -notlike "Dept_MyDepartment_Faculty"}
substituting the actual group name, the output is blank (just returns to the prompt)

Regarding comment from Jacob Durham:
I have RSAT and ran "Active Directory Module for Windows PowerShell" and pasted the script in that window but still get the same error.

Regarding comment by FOX:
I don't have access to Exchange Management Shell. I work for one of the departments at our organization, not for the central IT team and I don't have permissions to manage Exchange.
0
spmtCommented:
Hello,

sorry i have make a mistake

good one is :

Get-ADGroup -Filter {GroupCategory -eq "Distribution" -or Identity -notlike "Dept_MyDepartment_Faculty"} -Properties Members

or play with filter to get what you want.


do this on your AD or install Active Directory Remote Server Administration Tools to your workstation.

even if you install Active Directory Remote Server Administration Tools to your workstation , you will not have Exchange command so  you cannot do Get-DistributionGroup expect if you install remote tools for exchange


Thanks and Regards
0
donanderAuthor Commented:
spmt,

When I run this and substitute the actual name of the distribution group for "Dept_MyDepartment_Faculty" I get all the distribution groups in AD EXCEPT that group. I think -notlike should not be in there. What I want is to just get the names and email addresses in a .csv file for a distribution group whose name I supply in the script.
Thanks,
Don
0
FOXActive Directory/Exchange EngineerCommented:
Donander,
Test this on one group    (please create a folder on your c:drive named Temp)

Get-ADGroupMember 'GroupName' -Recursive | Get-ADUser -Properties Mail | Select-Object Name,Mail | Export-CSV -Path 'C:\temp\GroupName.csv' -NoTypeInformation
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
donanderAuthor Commented:
Code submitted by FOX does exactly what I want.
Sorry for the delay in testing.
Thanks!
Don
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.