Solved

Powershell inbox rule script - ExceptIfSentTo not adding multiple addreses

Posted on 2015-02-20
2
154 Views
Last Modified: 2015-02-20
I have a PowerShell script that I want to run every day (on schedule) that will add a rule to all new user mailboxes.
The rule is needed to move emails sent from our CRM into the users sent items folder.

add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010
$yesterday = (get-date).AddDays(-1)
Get-Mailbox -ResultSize unlimited |
   ? { $_.whenCreated -ge $yesterday } |
   % {
	Add-MailboxPermission -identity $_.identity -user administrator -AccessRights FullAccess
	New-InboxRule -Mailbox $_.identity -Name "Move BCc msgs to myself to Sent Items" -From $_.PrimarySmtpAddress.tostring() -ExceptIfMyNameInToOrCcBox $true -ExceptIfSentTo "sales@domain.com,everyone@domain.com" -MoveToFolder "$($_.alias):\Sent Items"
  }

Open in new window


The script completes successfully however upon checking the created only the first address of the exceptifsentto property is added.

How do I add multiple addresses to the Except if Sent to exception on the rule?

Kind regards
Antonio

Thanks
0
Comment
Question by:antonioking
2 Comments
 
LVL 69

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40621754
Use an array instead of a string, that is -ExceptIfSentTo "sales@domain.com","everyone@domain.com":
add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010
$yesterday = (get-date).AddDays(-1)
Get-Mailbox -ResultSize unlimited |
   ? { $_.whenCreated -ge $yesterday } |
   % {
     Add-MailboxPermission -identity $_.identity -user administrator -AccessRights FullAccess
     New-InboxRule -Mailbox $_.identity -Name "Move BCc msgs to myself to Sent Items" -From $_.PrimarySmtpAddress.tostring() -ExceptIfMyNameInToOrCcBox $true -ExceptIfSentTo "sales@domain.com","everyone@domain.com" -MoveToFolder "$($_.alias):\Sent Items"
   }

Open in new window

0
 

Author Comment

by:antonioking
ID: 40622141
Cheers!
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Utilizing an array to gracefully append to a list of EmailAddresses
Read this checklist to learn more about the 15 things you should never include in an email signature.
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question