I need to make a script to add a recipient in the "-From" section of a Exchange Online transport rule.
The script need to store in a variable the actuals recipients in the rule and add one more define by the user.
Here where i am:
#Get the rule and store in $rule variable
$rule = Get-TransportRule -Identity xxxxx-xxxxx-xxxx-xxxx-xxxxx
#Define the new recipient to add to the rule
$newuser = "[email protected]"
Thi is my problem:
I can get the actual recipient in the value $rule
with $rule.from
. The result is an array because it already have some recipients.
Command set-transportrule
accept the variable $rule.from
in the -from option but only take the first recipient in the array and not the others one
Set-TransportRule -Identity xxxxx-xxxxx-xxxx-xxxx-xxxxx -From $rule.from,$newuser
But it work if i use the variable with the index like this:
#Set the rule by re-adding the actual recipient and add $newuser
Set-TransportRule -Identity xxxxx-xxxxx-xxxx-xxxx-xxxxxc -From $rule.from[0],$rule.from[1],$newuser
I know I can find the number of recipients with $rule.from.count but after how can I generate the cmdlet set-transportrule
automatically with all the index present in the variable $rule.from
?
EX if i have 8 recipients in the array the command should be:
Set-TransportRule -Identity xxxxx-xxxxx-xxxx-xxxx-xxxxxc -From $rule.from[0],$rule.from[1],$rule.from[2],$rule.from[3],$rule.from[4],$rule.from[5],$rule.from[6],$rule.from[7],$newuser
Or maybe a better way is possible?
Thank you!
question from:
https://stackoverflow.com/questions/65866620/adding-array-value-in-a-cmdlet-set-transportrule 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…