Solved

Powershell inbox rule script - ExceptIfSentTo not adding multiple addreses

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

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

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

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Unified and professional email signatures help maintain a consistent company brand image to the outside world. This article shows how to create an email signature in Exchange Server 2010 using a transport rule and how to overcome native limitations …
In this video we show how to create a mailbox database 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 >> Data…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

691 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