Solved

Import  emailaddresses, exported from a distribution Group, to another DG

Posted on 2016-10-04
16
50 Views
Last Modified: 2016-10-05
Hi ,
I have a csv file with with the email addresses used by a DG. NOT the email address from the members of the DG , I'm referring to the smtp addresses used by the DG. For Instance: if the DG name is "Graduated students" with email addresses like:  gradstudents@domain.com , gradstudents@domain.onmicrosoft.com, gradstudents@mail.domain.com...
I need a sentence to import those email addresses into another DG in O365.
Thanks,
0
Comment
Question by:Ernesto Gallardo
  • 8
  • 8
16 Comments
 
LVL 40

Expert Comment

by:Subsun
ID: 41828638
For single group you can use following code..
Set-DistributionGroup testgroup -emailaddresses @{Add='gradstudents@domain.com','gradstudents@domain.onmicrosoft.com','gradstudents@mail.domain.com'}

Open in new window

With csv file...
Import-csv C:\input.csv | %{Set-DistributionGroup $_.GroupName -emailaddresses @{Add=($_.Email -Split ",")}}

Open in new window

Sample CSV
GroupName,Email
"Graduated students","gradstudents@domain.com,gradstudents@domain.onmicrosoft.com,gradstudents@mail.domain.com"

Open in new window

Emails will be updated to group 'Graduated students'

In case you if you don't have the export command..
Get-DistributionGroup "Graduated students" | Select-Object DisplayName,PrimarySmtpAddress,@{N=“Email”;E={($_.EmailAddresses |? {$_.PrefixString -ceq “smtp”} | % {$_.SmtpAddress}) -Join ","}} | Export-csv C:\group.csv -nti

Open in new window

0
 

Author Comment

by:Ernesto Gallardo
ID: 41828699
Thanks Again, I think we are close but , let me explain it more.
Since I'm performing a migration  of all the DGs managed by the exchange on premises to O365, I'm running a script that pre-creates the DG in O365 with the prefix "Cloud-" followed by the name of the Group to migrate. but this new pre-created group can't have the email addresses of the old one since they are still assigned to that old group.
So, I'm doing

Import-CSV C:\input.csv | ForEach {Get-DistributionGroup -Identity $_.name | select Displayname, emailaddresses} | Export-Csv C:\emailaddresses1.csv -NoTypeInformation
 
This will give me a csv file with 2 columms :
Column A= GroupName (e.g: ACE Portfolio)
Column B= Emailaddresses (e.g:  smtp:ace_port@mail.barry.edu SMTP:ace_port@barry.edu smtp:ace_port@barryuniversity.onmicrosoft.com x500:/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=7bba86b5543b4192a1d12a45115c7d91-ACE Portfolio X400:C=US;A= ;P=BARRYU;O=BUMAIN;S=ace?port; smtp:ace_port@barrynet.barry.edu)

After that I delete the groups from the exchange on premises and AD and  then After the DGs are also deleted from O365, then I should import the email addresses and remove the cloud- from the name of the group.
When running your sentence adjusted to my  names, etc.. this is the error I'm getting

"Cannot process argument transformation on parameter 'EmailAddresses'. Cannot
convert value "System.Collections.Hashtable" to type
"Microsoft.Exchange.Data.ProxyAddressCollection". Error: "MultiValuedProperty
collections cannot contain null values.
Parameter name: item"
    + CategoryInfo          : InvalidData: (:) [Set-DistributionGroup], Parame
   terBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-Distrib
   utionGroup
    + PSComputerName        : ps.outlook.com"

Looks like it can't read it in the format i have it...
0
 
LVL 40

Assisted Solution

by:Subsun
Subsun earned 500 total points
ID: 41828709
Try the following command to export..
Import-CSV C:\input.csv | ForEach {Get-DistributionGroup -Identity $_.name | select Displayname,@{N=“Email”;E={($_.EmailAddresses |? {$_.PrefixString -eq “smtp”} | % {$_.SmtpAddress}) -Join ","}}} | Export-Csv C:\emailaddresses1.csv -NoTypeInformation

Open in new window

To import..
Import-csv C:\input.csv | %{Set-DistributionGroup $_.GroupName -emailaddresses @{Add=($_.Email -Split ",")}}

Open in new window

0
 

Author Comment

by:Ernesto Gallardo
ID: 41828727
Thanks Subsun, but the file exported has empty the column for Email. Only the DisplayName is populated with the Groups.
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41828737
Just tested, It's working for me.. Does the group shows result for following command
Get-DistributionGroup TestGroup | select Displayname,@{N=“Email”;E={($_.EmailAddresses |? {$_.PrefixString -eq “smtp”} | % {$_.SmtpAddress}) -Join ","}}

Open in new window

If above fails, please post the result for..
Get-DistributionGroup TestGroup | select -exp EmailAddresses

Open in new window

0
 

Author Comment

by:Ernesto Gallardo
ID: 41828824
Hi Subsun,
I had to work on something else. I'll test this tonight and I'll let you know tomorrow. Thanks for all your help . I really appreciate it.
0
 

Author Comment

by:Ernesto Gallardo
ID: 41828992
The first one failed. It doesn't shows anything on the email part. Just empty.
The second one Works this way:

PS C:\Users\XXXXXX> Get-DistributionGroup "ACE Orlando" | select -exp EmailAddresses
SMTP:ace_orlando@barry.edu
smtp:ace_orlando@mail.barry.edu
smtp:ace_orlando@barryuniversity.onmicrosoft.com
x500:/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=76dcb5395beb4525b89e83e450035a
82-ACE Orlando
X400:C=US;A= ;P=BARRYU;O=BUMAIN;S=ace?orlando;
smtp:ace_orlando@barrynet.barry.edu
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41828996
Is that the exact result you get in powershell console?

Can you test this command and see result?
Get-DistributionGroup TestGroup | select Displayname,@{N=“Email”;E={($_.EmailAddresses |? {$_ -match “smtp”} | % {($_ -split ":")[1]}) -Join ","}}

Open in new window

0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:Ernesto Gallardo
ID: 41829859
DisplayName                                                 Email
 ACE Orlando                                             ace_orlando@barry.edu,ace_orlando@mail.barry.edu,ace_orl...
 This one looks good  with emails separated by coma..
Thank you Subsun
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41829867
Ok you can use the same to export the list..
Import-CSV C:\input.csv | ForEach {Get-DistributionGroup -Identity $_.name | select Displayname,@{N=“Email”;E={($_.EmailAddresses |? {$_ -match “smtp”} | % {($_ -split ":")[1]}) -Join ","}} | Export-Csv C:\emailaddresses1.csv -NoTypeInformation

Open in new window

0
 

Author Comment

by:Ernesto Gallardo
ID: 41829916
Looks like it should work but is stays like this:

PS C:\Users\gallo> Import-CSV S:\egallardo\test.csv | ForEach {Get-DistributionGroup -Identity $_.name | select Displayname,@{N="Email";E={($_.EmailAddresses |? {$_ -match "smtp"} | % {($_ -split ":")[1]}) -Join ","}} | Export-Csv S:\egallardo\Migration\emailaddresses2.csv -NoTypeInformation
>>
>>
And file emailaddresses2.csv is not created.
 I even reduce the amount of DGs in test.csv   to 19 and still....nothing.it wont come out of that state...
 I had to ctrl+C  to get out of that state.
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 41829931
Ah syntax error.. Missed the closing curly brace for ForEach ..
Import-CSV C:\input.csv | ForEach {Get-DistributionGroup -Identity $_.name | select Displayname,@{N=“Email”;E={($_.EmailAddresses |? {$_ -match “smtp”} | % {($_ -split ":")[1]}) -Join ","}}} | Export-Csv C:\emailaddresses1.csv -NoTypeInformation

Open in new window

0
 

Author Comment

by:Ernesto Gallardo
ID: 41830117
Yes, That was it , perfect , Now it is created with that format , separated by coma only .
So to later import them into the pre-created ones in O365:
1- Delete from O365 those DGs that I already have pre-created them in O365 and also their email addresses exported.
2.-Remove the Cloud- prefix to that list of pre-created DGs
3.- Now I'm doing : Import-csv S:\Migration\emailaddresses2.csv | %{Set-DistributionGroup -Identity $_.Displayname -emailaddresses @{Add=($_.Email -Split ",")}}       (As you suggested)  And Is working Just Fine.
I just need to find a better way now to remove the Cloud- and to reassign the correct email address as the one to use to reply. But I'll try to find it by my self, So far you have Helped me A LOT!!!
Thank you So much  Subsun
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41830125
You are welcome!..
1
 

Author Closing Comment

by:Ernesto Gallardo
ID: 41830140
Susbsun,is the Best, Always replied quickly, and he was helping me all the way until the correct sentence was created. And all that at any time, You guys rock!!!!
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41830203
Happy to help!
1

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
A procedure for exporting installed hotfix details of remote computers using powershell
In this video we show how to create a Distribution Group in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >>…
This video discusses moving either the default database or any database to a new volume.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now