jthibeault
asked on
Recursively Export Distribution List Users Exchange 365
I have had a few requests for this and have not been able to produce so im turning to some experts:
We have a distribution list called "all companies". In this list are more distribution lists named "all boston staff", "all New Yrok Staff" etc. I need a way to export to a csv, all of the members of the "all companies" distribution list that has all of the members of the child lists. I know this can be done in powershell but every port I have found has fallen flat, given an error or other.
We are using office365 and not an on premise exchange solution.
Thanks in advance.
We have a distribution list called "all companies". In this list are more distribution lists named "all boston staff", "all New Yrok Staff" etc. I need a way to export to a csv, all of the members of the "all companies" distribution list that has all of the members of the child lists. I know this can be done in powershell but every port I have found has fallen flat, given an error or other.
We are using office365 and not an on premise exchange solution.
Thanks in advance.
Hello and thanks for your question.
You can use the Get-DistributiongroupMembe r command with Office 365 Exchange Online.
Here is the official article from Microsoft:
http://gallery.technet.microsoft.com/office/Get-Distribution-Group-4f0ad588
Hopefully you can follow this ok, but if you need a hand let me know.
Good Luck
James
You can use the Get-DistributiongroupMembe
Here is the official article from Microsoft:
http://gallery.technet.microsoft.com/office/Get-Distribution-Group-4f0ad588
Hopefully you can follow this ok, but if you need a hand let me know.
Good Luck
James
ASKER
@subsun
I get the following error: Pipeline not executed because a pipeline is already existing. Pipelines cannot be executed concurrently.
The CSV is created with only one user.
I get the following error: Pipeline not executed because a pipeline is already existing. Pipelines cannot be executed concurrently.
The CSV is created with only one user.
I just tested it.. but it's not throwing error for me..
Anyways try this modified code and see if you get any error...
Anyways try this modified code and see if you get any error...
filter Get-GroupRecurse {
if($_.RecipientType -match "Group") {
Get-DistributionGroupMember $_.Name | Get-GroupRecurse
} else {
$_
}
}
$(Foreach ($member in Get-DistributionGroupMember "all companies"){
$member | Get-GroupRecurse | Select -Unique}) | Export-Csv C:\report.csv -NTI
ASKER
@James_Hodge
All works well except I dont get a list of users in the CSV, only a column that has this: 27c87ef9bbda4f709f6b4002fa 4af63c
Not sure whats up with that.
All works well except I dont get a list of users in the CSV, only a column that has this: 27c87ef9bbda4f709f6b4002fa
Not sure whats up with that.
ASKER
@subsun:
Same deal unfortunately. Although this time I get 14 users and the error only appears twice instead of four times. Should I send you the entire script im running?
Same deal unfortunately. Although this time I get 14 users and the error only appears twice instead of four times. Should I send you the entire script im running?
So did you modify/add anything in the code which I posted?
ASKER
@subsun:
Its just the normal stuff we have in every script to connect to E365:
Set-ExecutionPolicy Unrestricted -Force
chdir c:\
$LiveCred = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic –AllowRedirection
Import-PSSession $Session
filter Get-GroupRecurse {
if($_.RecipientType -match "Group") {
Get-DistributionGroupMembe r $_.Name | Get-GroupRecurse
} else {
$_
}
}
$(Foreach ($member in Get-DistributionGroupMembe r "drg@dresourcesgroup.com") {
$member | Get-GroupRecurse | Select -Unique}) | Export-Csv C:users\jthibeault\desktop \report.cs v -NTI
Its just the normal stuff we have in every script to connect to E365:
Set-ExecutionPolicy Unrestricted -Force
chdir c:\
$LiveCred = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic –AllowRedirection
Import-PSSession $Session
filter Get-GroupRecurse {
if($_.RecipientType -match "Group") {
Get-DistributionGroupMembe
} else {
$_
}
}
$(Foreach ($member in Get-DistributionGroupMembe
$member | Get-GroupRecurse | Select -Unique}) | Export-Csv C:users\jthibeault\desktop
Hmm.. ok didn't see any issues..Also I a not able to reproduce the issue.. I will try to come with something else when i get a chance..
Try this and see if it gives you same error..
If above is not working then you may also try the code from following article. The code is for Exchange 2010 however you can comment out Add-PSSnapin line and use it..
https://christopherlaw.com/2012/10/get-recursive-group-membership-of-distribution-group-powershell/
filter Get-GroupRecurse {
if($_.RecipientType -match "Group") {
Get-DistributionGroupMember $_.Name | Get-GroupRecurse
} else {
$_
}
}
$Report = @()
Foreach ($member in Get-DistributionGroupMember "all companies"){
$Report += $member | Get-GroupRecurse | Select -Unique
}
$Report | Export-Csv C:\report.csv -NTI
If above is not working then you may also try the code from following article. The code is for Exchange 2010 however you can comment out Add-PSSnapin line and use it..
https://christopherlaw.com/2012/10/get-recursive-group-membership-of-distribution-group-powershell/
ASKER
@Subsun
Thanks for your continued effort. I ran your changes as suggested and I get the following error: "Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently"
I get this four times followed by a csv that only has a handful of users. I tried inserting the alias of the Distribution List in quotes and the Email Address. Each time I get the same error and the same incomplete csv file. When I use the display name I get: "The script failed due to a cal depth overflow. The call Depth reached 1001 and the maximum is 1000."
I then tried the script in the link you sent but im not sure I get that one right either as I get the following error: "The term 'else' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again."
I quoted out section #16. I have tried removing the else from section 32. That gives no error but the csv has nothing in it.
******EDIT: Looks like I didnt remove the numbers from the post. After removing the numbers the script works from your link.
I still have an issue where its not outputting to a csv even though i put in the command: export-csv -path "C:\report.csv" at the end i just get: "cmdlet export-csv at command pipeline position 1"
"Supply Values for the following parameters: InputObject:"
Any suggestions on how I can edit that script to output to a csv?
Thanks for your continued effort. I ran your changes as suggested and I get the following error: "Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently"
I get this four times followed by a csv that only has a handful of users. I tried inserting the alias of the Distribution List in quotes and the Email Address. Each time I get the same error and the same incomplete csv file. When I use the display name I get: "The script failed due to a cal depth overflow. The call Depth reached 1001 and the maximum is 1000."
I then tried the script in the link you sent but im not sure I get that one right either as I get the following error: "The term 'else' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again."
I quoted out section #16. I have tried removing the else from section 32. That gives no error but the csv has nothing in it.
******EDIT: Looks like I didnt remove the numbers from the post. After removing the numbers the script works from your link.
I still have an issue where its not outputting to a csv even though i put in the command: export-csv -path "C:\report.csv" at the end i just get: "cmdlet export-csv at command pipeline position 1"
"Supply Values for the following parameters: InputObject:"
Any suggestions on how I can edit that script to output to a csv?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try..
Open in new window