Saturday, November 22, 2014

Cannot convert value Microsoft.Exchange.Data.MultiValuedProperty



I recently needed a script to add new individuals to the accept message only permissions on a large list of distribution groups. It needed to be additive so that it was not overwriting the existing permissions.  I found several examples and modified them to suite my needs:


$allowedDL = gc C:\scripts\AllUserLock\allowedDL.txt
$People = gc C:\scripts\AllUserLock\People.txt
$Groups = gc C:\scripts\AllUserLock\Groups.txt
ForEach ($Group in $Groups) {

   Set-DistributionGroup $Group -AcceptMessagesOnlyFrom((Get-DistributionGroup $Group).AcceptMessagesOnlyFrom + $People)
   Set-DistributionGroup $Group -AcceptMessagesOnlyFromDLMembers((Get-DistributionGroup $Group).AcceptMessagesOnlyFromDLMembers + $alloweddl)

}


This worked great until I realized I’d missed adding a couple groups due to interruptions as I was working on this task. When I added the new groups to the allowedDL.txt file and ran the script again I got this error - Cannot convert value Microsoft.Exchange.Data.MultiValuedProperty.  I knew the syntax was correct.  The values that could not be converted were clearly the new distribution lists in the allowedDL.txt file. My web searches found several references to this error but no solutions or explanations. In fact I recognized it from an issue I have had previously importing trusted domains into Office 365 EOP.  A call to Microsoft support services was no help on that.

What I eventually found was that when I added the 2 new DL’s to allowedDL.txt I had added several trailing carriage returns. What happens is the scripts builds a text string and added it to the existing permissions.  It looks like “DL1,DL2,DL3DL4”.  Those carriage returns cause the string to look like “DL1,DL2,DL3DL4                    ” You cannot add white space to a multi-property string as that white space has value.White space is not interpreted a null value.

Removing the trailing carriage returns in the input file fixed the issue….. now I need to return to working on importing my trusted senders :