Home > Software design >  PowerShell: using @{Add=''} sometimes work and sometimes it does not
PowerShell: using @{Add=''} sometimes work and sometimes it does not

Time:06-16

When an object can have multiple values on an object like, I use most of the time: -Object @{Add=''} or -Object @{Remove=''}. But I notice that this not works all the time, than you need to set all the values because other wise it replaces the existing values.

For example, when I use:

Set-Mailbox "Contoso Executives" -GrantSendOnBehalfTo @{Add='[email protected]','[email protected]'}

The @{Add=''} is working. But when I use:

Set-RetentionPolicy "MRM Policy" -RetentionPolicyTagLinks @{Add='tag1','tag2'}

I get the following error:

Cannot convert value "System.Collections.Hashtable" to type

Why does this happens? RetentionPolicyTagLinks can have multiple values in the same way as GrantSendOnBehalfTo can have.

CodePudding user response:

Your issue is within the format of your RetentionPolicyTagLinks parameter.

Try the documentation below to help you with storing it in a variable first:

https://docs.microsoft.com/en-us/exchange/add-or-remove-retention-tags-exchange-2013-help

  • Related