Share via

Add multiple members to multiple groups.

Anonymous
2018-11-22T13:25:47+00:00

I'm trying to add multiple members into multiple groups.

Seeing as Add-UnifiedGroupLinks accepts multiple values for the -Links parameter delimited by commas, I created a file that looks like the following:

Identity:Links

group1:"user1@domain","user2@domain","user3@domain"

group2:"user2@domain"

group3:"user1@domain","user2@domain","user3@domain","user4@domain"

group4:"user3@domain"

I then ran the following command:

Import-Csv group-members.csv -Delimiter : | foreach{Add-UnifiedGroupLinks -Linktype Members -Identity $_.Identity -Links $_.Links -WhatIf}

Unfortunately that doesn't get parsed how I expected it to be parsed.

The lines where there only a single value would be passed onto the -Links parameter works fine:

What if: Updating unified group links "group2".

But the lines with multiple values kicks out the following error:

Couldn't find object "user1@domain,"user2@domain","user3@domain"". Please make sure that it was spelled correctly or specify a different object.

    + CategoryInfo          : NotSpecified: (group1:UnifiedGroupIdParameter) [Add-UnifiedGroupLinks], ADNoSuchObjectException

    + FullyQualifiedErrorId : [Server=ME2PR01MB3556,RequestId=3cb21198-fc68-466c-bacc-f8fa427278b3,TimeStamp=22/11/2018 12:40:05 PM] [Failure Category=Cmdlet-ADNoSuchObjectException] 6B58DCE2,Microsoft.Exchange.Management.RecipientTasks.AddUnifiedGroupLinks

    + PSComputerName        : outlook.office365.com

Notice that the end quote goes missing from the first value and ends up after the last value.

I removed the quotes from around each value, and the error becomes:

Couldn't find object "user1@domain,user2@domain,user3@domain". Please make sure that it was spelled correctly or specify a different object.

Slightly different, here the values are parsed as a whole without the strange attempt at parsing the values that happens when the values are within quotes.

I'm quite well verse with shell scripting on *nix, but I'm new to PowerShell. I've had a look at the docs, but I'm somewhat at a loss as to how can I get the values to be passed on individually, rather than as a monolithic object that doesn't exist?

Cheers.

Microsoft 365 and Office | Subscription, account, billing | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2018-11-22T14:16:58+00:00

Hi Adam,

Thank you for posting your query on Microsoft Community. Regarding the PowerShell script requirement/issue. I’d like to involve our dedicated Script Center Support team in finding the solution for you, please post your question in this forum and there experts’ will focus on the issue to get it resolved more efficiently.

Your time and understanding will be highly appreciated.

Best regards,

Shyamal

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful