question

HenkSteenwijk-5040 avatar image
0 Votes"
HenkSteenwijk-5040 asked LucasLiu-MSFT commented

Adding an alias using Set-UnifiedGroup with groups in a csv file

Hi everyone,

I've been tasked with adding an e-mail alias @domain.com to our existing group mailboxes, i've already figured out I can achieve this via the Set-UnifiedGroup command, single line way I've used Set-UnifiedGroup -Identify "Identity of group" -EmailAddresses @{Add=#identitynameofgroup@domain.com"} which seems to work once verified via the Get-UnifiedGroup command.

But now I have to do so for the other 291 groups.

I know this can be achieved via the Import-CSV command but i'm failing in setting up a usable command to import the list from the csv and add the alias accordingly.

Can anyone give me a nudge in the right direction?

My csv file consists of a single colomn with the names of the groups I need to add an alias too, the name of the colomn is Identity.

Many thanks in advanced.

Cheers,
Henk Steenwijk

office-exchange-server-administration
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AshokM-8240 avatar image
0 Votes"
AshokM-8240 answered LucasLiu-MSFT commented

Hi @HenkSteenwijk-5040

Try the below command,

Import-Csv 'C:\test.csv' | ForEach-Object { Set-UnifiedGroup -Identity $.Identity -EmailAddresses @{Add=$.SecondaryEmail}}

<dollar underscore dot> before identity and secondaryemail

test.csv is the name of the CSV file which should have 2 columns, one with Identity - name of the group as one character and second with the new secondary email address as SecondaryEmail.

If the above suggestion helps, please click on "Accept Answer" and upvote it.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @HenkSteenwijk-5040 ,
Agree with AshokM.

Please run the following commannd to add the secondaryemail address for the Microsoft 365 group.

 Import-Csv 'C:\test1.csv' | ForEach-Object { Set-UnifiedGroup -Identity $_.Identity -EmailAddresses @{Add=$_.SecondaryEmail}}

According to the error message, please make sure the email address entered in your CSV file is valid.

The following screenshot is the test in lab environment, hope it can help you better understand.
99520-inkedcapture3-li.jpg



If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.




0 Votes 0 ·
inkedcapture3-li.jpg (727.6 KiB)
HenkSteenwijk-5040 avatar image
0 Votes"
HenkSteenwijk-5040 answered AshokM-8240 edited

Hi AshokM,

Thanks for the quick response, so I now have a changed my csv to contain two colomns, the first being the Identity and second with the new secondary email addresses.

The output I recieve once i start the script is:


PS C:\Windows\system32> Import-CSV 'C:\temp\identity1.csv' | ForEach-Object { Set-UnifiedGroup -Identity $.Identity -EmailAddresses @{Add=$.SecondaryEmail}}

Cannot process argument transformation on parameter 'EmailAddresses'. Cannot convert value "System.Collections.Hashtable" to type "Microsoft.Exchange.Data.ProxyAddressCol
lection". Error: "MultiValuedProperty collections cannot contain null values.
Parameter name: item"
+ CategoryInfo : InvalidData: (:) [Set-UnifiedGroup], ParameterBindin...mationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-UnifiedGroup
+ PSComputerName : outlook.office365.com

I think i'm doing something wrong with the csv file but i'm not sure.

Cheers,
Henk

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

CSV should look like below,

99350-image.png



Just import the CSV using Import-CSV 'C:\temp\identity1.csv' and check if the columns and values are showing properly in the powershell. Then try the Set command. Please note it is <dollarunderscoredot>Identity and <dollarunderscoredot>SecondaryEmail

0 Votes 0 ·
image.png (3.2 KiB)
HenkSteenwijk-5040 avatar image
0 Votes"
HenkSteenwijk-5040 answered AshokM-8240 commented

Hi all,

Ashok was right, the command was fine.

I figured out where it went wrong too, my excel saved the file as a csv but instead of being seperated with a , it used a ; which resulted in the errors post before.

Thanks for the quick response.

Cheers,
Henk

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Glad to know that it has been resolved and the suggestion helped :)

0 Votes 0 ·