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 $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
- pvanberloSteel ContributorTry this:
New-InboxRule -Mailbox $SingleImport.PrimarySMTPAddress -From user.name@extdomain.com -MyNameInToBox $True -SubjectContainsWords '["Receipt Copy"] Hello' -Name EmailRule -MoveToFolder “$($SingleImport.PrimarySMTPAddress):\Sent Items"- Robert BollingerBrass 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
- pvanberloSteel 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.