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

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,
Ernesto GallardoAsked:
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.

SubsunCommented:
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
Ernesto GallardoAuthor Commented:
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
SubsunCommented:
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
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Ernesto GallardoAuthor Commented:
Thanks Subsun, but the file exported has empty the column for Email. Only the DisplayName is populated with the Groups.
0
SubsunCommented:
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
Ernesto GallardoAuthor Commented:
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
Ernesto GallardoAuthor Commented:
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
SubsunCommented:
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
Ernesto GallardoAuthor Commented:
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
SubsunCommented:
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
Ernesto GallardoAuthor Commented:
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
SubsunCommented:
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

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
Ernesto GallardoAuthor Commented:
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
SubsunCommented:
You are welcome!..
1
Ernesto GallardoAuthor Commented:
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
SubsunCommented:
Happy to help!
1
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.