Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Powershell inbox rule script - ExceptIfSentTo not adding multiple addreses

Posted on 2015-02-20
2
Medium Priority
?
176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 71

Accepted Solution

by:
Qlemo earned 2000 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

On September 18, Experts Exchange launched the first installment of the Help Bell, a new feature for Premium Members, Team Accounts, and Qualified Experts. The Help Bell will serve as an additional tool to help teams increase question visibility.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
how to add IIS SMTP to handle application/Scanner relays into office 365.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

636 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