HubDamian
HubDamian

Reputation: 5

Powershell foreach Exchange Online InboxRule issue

I'm having an issue when trying to complete my script.

I'm trying to create a rule for couple of users: (if message arrives from (x), move to Inbox). This is the script I wrote:

 $names = @{"[email protected]","[email protected]"}

Loop

foreach($name in $names){
    Write-Host "Moving the message for $name"
    new-inboxrule -Name "MoveFromMailchimp" -Mailbox $name -MoveToFolder 
    "$name:\Inbox" -From "senderEmailAddress" -StopProcessingRules: $false
}

However it throws an error upon $name:\Inbox, saying it does not want to take ":".

Does anyone have any ideas?

Upvotes: 0

Views: 148

Answers (1)

guiwhatsthat
guiwhatsthat

Reputation: 2434

You need to escape your variable in the string.

Try: "$($name):\Inbox"

Upvotes: 1

Related Questions