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 13, 2021Steel Contributor
Try this:
New-InboxRule -Mailbox $SingleImport.PrimarySMTPAddress -From user.name@extdomain.com -MyNameInToBox $True -SubjectContainsWords '["Receipt Copy"] Hello' -Name EmailRule -MoveToFolder “$($SingleImport.PrimarySMTPAddress):\Sent Items"
New-InboxRule -Mailbox $SingleImport.PrimarySMTPAddress -From user.name@extdomain.com -MyNameInToBox $True -SubjectContainsWords '["Receipt Copy"] Hello' -Name EmailRule -MoveToFolder “$($SingleImport.PrimarySMTPAddress):\Sent Items"
Robert Bollinger
Sep 13, 2021Brass Contributor
So that seemed to work!! Thanks for your help. However now i have a different problem, instead of operating on each object (each user in my list) it only applies the mailbox rule to the LAST user in the list.
I have not seen that before? Any ideas?
Thanks
- pvanberloSep 14, 2021Steel ContributorWould 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.- Robert BollingerSep 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 14, 2021Brass Contributor
I forgot to post this last night:
$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 TestEmailRule -MoveToFolder “$($SingleImport.PrimarySMTPAddress):\Sent Items"
}Thats my complete script.