Sep 13 2021 10:29 AM
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 $SingleImport.PrimarySMTPAddress -From user.name@extdomain.com -MyNameInToBox $True -SubjectContainsWords '["Receipt Copy"] Hello' -Name EmailRule -MoveToFolder $SingleImport.PrimarySMTPAddress:\"Sent Items"
My input list has a single Column:
PrimarySMTPAddress
I am getting this error when trying to run the script:
A positional parameter cannot be found that accepts argument ':\Sent Items'.
+ CategoryInfo : InvalidArgument: (:) [New-InboxRule], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,New-InboxRule
+ PSComputerName : outlook.office365.com
Any ideas?
Thanks,
Robert
Sep 13 2021 02:26 PM
Sep 13 2021 03:49 PM - edited Sep 13 2021 03:49 PM
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
Sep 13 2021 05:44 PM
Sep 14 2021 07:06 AM
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.
Sep 14 2021 08:54 AM - edited Sep 14 2021 09:01 AM
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.
Sep 14 2021 05:13 PM
Sep 15 2021 04:20 AM
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.