Forum Discussion
Robert Bollinger
Sep 13, 2021Brass Contributor
Mailbox Rules, PowerShell and Scripting.
Hey Guys, I am trying to create a powershell script that will create a mailbox rule in each users mailbox, based on an input list. Here is what i have so far: New-InboxRule -Mailbox $S...
pvanberlo
Sep 14, 2021Steel Contributor
Would need a bit more of your script. But generally you’d do something like this:
$Mailboxes = Import-CSV .\mailboxes.csv
ForEach ($Mailbox in $Mailboxes) {
// Insert the code above but replace SingleImport with Mailbox
}
On mobile right now, so can’t make it pretty etc.
$Mailboxes = Import-CSV .\mailboxes.csv
ForEach ($Mailbox in $Mailboxes) {
// Insert the code above but replace SingleImport with Mailbox
}
On mobile right now, so can’t make it pretty etc.
Robert Bollinger
Sep 14, 2021Brass Contributor
ok so here is where i am on it. So far this almost works:
$Importlist = Import-CSV Test_Email_Rule.csv
foreach ($SingleImport in $importlist)
{
New-InboxRule -Mailbox $($SingleImport.PrimarySMTPAddress) -From user.name@domain.com -MyNameInToBox $True -SubjectContainsWords '["Receipt Copy"] Hello' -Name RAKEmailG4 -MoveToFolder "$($SingleImport.PrimarySMTPAddress):\Sent Items"
}
The above script appears to work, however when it comes to moving the item to the users sent items folder it fails.
If i remove MovetoFolder Option and select -Deletemessage $True then it works. However i dont want to delete the message.
I am attaching an screenshot as well.
Showing error
- pvanberloSep 15, 2021Steel ContributorHmm. The error message seems to indicate a connection failure. Not sure what might be causing it, but the syntax should be correct reading the docs.
- Robert BollingerSep 15, 2021Iron Contributor
Thanks for the response. Actually it turns out the problem was related to not having full mailbox access rights to the mailboxes in which i am trying to create the rule. I was testing with my 3 test accounts and those worked as expected. However my other test accounts did not.
I did some additional checking and found an article covering the need for full mailbox rights, but only when setting a rule which touches the users mailbox folders.
Thanks for your help.