Solved

Powershell inbox rule script - ExceptIfSentTo not adding multiple addreses

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
In this video we show how to create an Accepted Domain 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 Mail Flow >> Ac…
how to add IIS SMTP to handle application/Scanner relays into office 365.

809 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