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.