Exchange 2010 Set-DistributionGroup error

I am working with the Set-Distributiongroup -AcceptMessagesOnlyFromSendersOrMembers attribute. This is a multi-value property but when I use a csv file input with multiple values(separated by a comma), powershell appears to see it as a single value and can’t find it.

[pre]

$group = import-csv c:\temp\restrictedgroups.csv

foreach($i in $groups)

{

$name = $i.group

$name

$senders = $i.senders

$senders

set-distributiongroup $name -AcceptMessagesOnlyFromSendersOrMembers $senders

}

[/pre]

Echoed on screen

#Employees-City ($name)

#Restricted Senders-City, #Restricted Senders ($senders)

The returned error:

Couldn’t find object “#Restricted Senders-City, #Restricted Senders”. Please make sure that it was spelled correctly or specify a different object.

It is not the spaces in the name of the group. If I put a single entry into the Senders column, such as #Restricted Senders, it works correctly. It only errors when there are multiple values in that column.

 

Any help would be appreciated.

 

 

You likely just need to change it to an array.

Verify that

$i.Senders.gettype()
comes back as a string.

If it does, you can turn it into an array with the -split operator.

PS> $example = "value 1, value 2"
PS> $example -split ", "
value 1
Value 2

I tried that already and it didn’t work either. If I do the command as a one liner for a single group:

[pre]
set-distributiongroup xxx -<wbr />AcceptMessagesOnlyFromSendersO<wbr />rMembers "group1","group2","group3","jo<wbr />hn.doe@xyz.com"
[/pre]
It works as it is supposed to, no array needed. What looks to be happening by using the CSV file, is grabbing the value $_.Senders in the foreach loop outputs it to the parameter like this: ""group1","group2","john.doe@<wbr />xyz.com"". Wrapping it in an additional set of double quotes.
This makes the parameter think it's a single item and it can't find it. So now you would think, easy enough to fix, remove the beginning and end "" and then $_.Senders would be "group1","group2","john.doe@<wbr />xyz.com", but this is not the case. Removing the beginning and end "" causes $_.Sender to read as group1","group2","john.doe@<wbr />xyz.com, which causes a different error, about not being able to convert the value of the 1st character to a multiValuedProperty.
So if I am going to use a csv file input and there are well 100 of these I need to do, I need some way to extract "group1","group2","group3","jo<wbr />hn.doe@xyz.com" from ""group1","group2","john.doe@<wbr />xyz.com"" as it seems according to the MS help for this particular property, proper "" around each value is necessary.

Sorry if this comes through twice. Having some issues today (probably self-inflicted :))

I tried that and it didn’t work either. If I do the command as a one liner for a single group, below, it works as intended:

[pre]

set-distributiongroup xxx -AcceptMessagesOnlyFromSendersOrMembers “group1",“group2”,“group3”,"john.doe@xyz.com

[/pre]

However using a csv input with a foreach loop appears to be the issue.

If my senders column has this value: “group1",“group2”,“group3”,"john.doe@xyz.com” and I use $_.Senders as the parameter value, the error will be:

Couldn’t find object ““group1",“group2”,“group3”,"john.doe@xyz.com””. Please make sure that it was spelled correctly or specify a different object.

Please note the extra set of double quotes around the value of $_.Senders. It appears to be seeing it as a single value. However if I remove the leading and trailing “” from the csv column (group1",“group2”,“group3”,"john.doe@xyz.com) a new error is triggered …Unable to convert G to a MultiValuedProperty…

So it appears that in order to provide the value as an actual MultiValuedProperty I need to be able to extract “group1",“group2”,“group3”,"john.doe@xyz.com” from ““group1",“group2”,“group3”,"john.doe@xyz.com””, retaining a single set of leading and trailing double quotes.

What error do you get when trying to split the string and pass that result in?

Your one-liner example

set-distributiongroup xxx -AcceptMessagesOnlyFromSendersOrMembers "group1","group2","group3","john.doe@xyz.com"

is using an array (“group1",“group2”,“group3”,"john.doe@xyz.com”), so the other method should work. Unless there’s some quirky Exchange Online behavior going on, which that module is absolutely known for.

You’re right that PowerShell is treating your CSV data as a single value though. Doesn’t matter what you stick in any given cell, a single cell gets interpreted as a single value when you use Import-Csv. This is why you can’t pass that value in directly, regardless of how you alter it in the CSV.

Going from what you have in that cell, I would isolate those values like so…

PS> $str = '"group1","group2","group3","john.doe@xyz.com"'
PS> $str
"group1","group2","group3","john.doe@xyz.com"
PS> $str -replace '"' -split ","
group1
group2
group3
john.doe@xyz.com