Solved

Powershell inbox rule script - ExceptIfSentTo not adding multiple addreses

Posted on 2015-02-20
2
144 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 68

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
To show how to generate a certificate request in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Servers >> Certificates…
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now