Forum Discussion
Mailbox Rules, PowerShell and Scripting.
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
$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, 2021MCTHmm. 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.
- 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.