Multi-valued attributes are attributes that can contain more than one value. Email-addresses of users, Accept messages only from attribute of Distribution groups are some examples of multi-valued attributes. Modifying or retrieving single-valued attributes through shell are quite simple whereas caution needs to be exercised when dealing with multi-valued ones. Powershell, by default, tends to replace a value instead of appending when Set commands are used. So multi-valued properties can be accidentally over-written..
Consider a distribution group ‘Test DL’ which is set to accept messages only from ‘User1’, ‘User2’ and ‘User3’. We can query the attribute using the command below :
Get-DistributionGroup "Test DL" | fl Name,AcceptMessagesOnlyFrom
Now, when ‘User 4’ needs to be added to the same property we execute the command below:
Set-DistributionGroup "Test DL" -AcceptMessagesOnlyFrom 'User4'
However, when we execute the first command again, we find that the existing users have been replaced by ‘User4’
To avoid replacing the existing users, the below command can be used instead:
Set-DistributionGroup "Test DL" -AcceptMessagesOnlyFrom @{Add = "User4"}
To remove ‘User4’ from the accept messages only from parameter, the command can be altered to:
A single command can be used to remove ‘User1’ and add ‘User5’ to the attribute:
Set-DistributionGroup "Test DL" -AcceptMessagesOnlyFrom @{Remove = "User1" ; Add="User5"}
The general syntax would be:
Set-cmdlet ‘Identity ’-MultivaluedAttributeSwitch @{Add = “value1”,”value2”,”value3” ; Remove = “value4”,”value5”}
Just happened to write the script below to over come throttling policy of time- To include a sleep parameter:
ReplyDelete$mbx=get-mailbox
$mbx|Foreach{Search-Mailbox $_.identity -SearchQuery "Subject:'content'" -EstimateResultOnly ;[System
.Threading.Thread]::Sleep(500); }