$uri = "https://your.mailbox.server/powershell" $mbx = "username@domain.com" $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $uri -Authentication Basic -Credential $cred -AllowRedirection Import-PSSession $session # Get existing mailbox rules $rules = Get-InboxRule -Mailbox $mbx # Get properties that will contain an address $params = 'ExceptIfFrom','ExceptIfSentTo','ForwardAsAttachmentTo','ForwardTo','From','RedirectTo','SentTo' # SMTP format is {"Display Name" [SMTP:alias@domain.tld]} # LegacyDN format is {"Display Name" [EX:/distinguished/name]} # we need to identify every rule that contains a legacyDN in any of the members that can contain an SMTP address # pull every rule that contains a value for any of the address inboxrule properties # iterate through rules foreach ($rule in $rules) { # grab rule identity - need this for Set-InboxRule $ruleid = $rule.RuleIdentity # iterate through each address parameter foreach ($param in $params) { # assign rule.parameter to a variable for convenience $rparam = $rule.$param # if rparam contains a value, do stuff if ($rparam) { # iterate through array of addresses in $rparam - we need the index of the array for this one for ($i = 0; $i -lt $rparam.count; $i++) { #check if EX or SMTP if ($rparam[$i] -clike "*EX*") { # extract the DN from the output $legacydn = ($rparam[$i] -csplit '\[EX\:')[1] -Replace "]", "" # get the SMTP address for each DN $smtp = Get-Recipient $legacydn | Select-Object PrimarySMTPAddress # replace DN with SMTP address $rparam[$i] = $rparam[$i] -replace '\[(.*?)\]',('[SMTP:'+$smtp.PrimarySMTPAddress.ToString()+']') } } # now that our $rules variable has been updated, we SHOULD be able to take the same rule by ID and update the same parameter $ruleparam = @{$param = $rparam} Set-InboxRule $ruleid @ruleparam -Mailbox $mbx } } }