We are trying to make a rule where if a message has XXXXX in the subject then move to the Junk Folder.

I have granted my user full access rights to all mailboxes on the server.

I have confirmed I can create the rule with users individually

The issue is that the command works for some users and not for others. Similarily the command is creating multiple copies of the rule for some users and not for others. There does not seem to be any pattern to this at all.

Here is my command

    [PS] C:\Windows\system32>get-mailbox -organizationalunit "supernova.local/Active Users" -resultsize unlimited| foreach {
 new-inboxrule -name "Spam Move" -mailbox kerry -MoveToFolder "kerry:\Junk E-Mail" -SubjectContainsWords "[Spam:" -StopP
rocessingRules $true -confirm:$false -force }

When you do this for an idividual user. (in this case "Kerry") here is the output.

    Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
    + CategoryInfo          : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [],
    + FullyQualifiedErrorId : RemotePipelineExecutionFailed

Name                          Enabled                       Priority                      RuleIdentity
----                          -------                       --------                      ------------
Spam Move                     True                          1                             13037078695330709505
Spam Move                     True                          1                             13109136289368637441
Spam Move                     True                          1                             13181193883406565377

When done for mulitple users by replacing "Kerry" with $($_.Alias) it only works for some users. Other get double or more copies of the rule, while other users do not get it at all.....

Very strange.

What could I be missing here?


The first error is because PowerShell implicit remoting doesn't support a piped ForEach. You would have to assign to a variable then do ForEach In like:

$MBs = Get-Mailbox -OrganizationalUnit "supernova.local/Active Users" -ResultSize Unlimited

ForEach($MB in $MBs)
New-InboxRule -Name "Spam Move" -Mailbox $MB -MoveToFolder "kerry:\Junk E-Mail" `
-SubjectContainsWords "[Spam:" -StopProcessingRules $true -Confirm:$false -Force

The second issue I see is that you are specifying -Mailbox on in the command, but that should be coming from the pipeline. In the above example since it's in ForEach reference the iteration variable $MB instead. I'm guessing the folder ID you're specifying in -MoveToFolder would also have to be different, perhaps something like $($MB.SamAccountName):\Junk E-Mail`. You may have to tinker with some of this.

Please bear in mind I came across this thread because I'm having my own troubles with New-InboxRule, so it may still not work. Because of these other issues I'm not able to test this. That said everything I've pointed out here is general syntax, and should hold true regardless.

Let me know how it goes...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.