You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerShell批量创建Exchange Online收件箱规则报错求助

Fixing the Inbox Rule Script Error with Folder Paths

Let's break down the issues in your script and fix them step by step:

1. Correct the Array Definition

First, you've used @{} (a hashtable) to define your list of user emails, but you need a simple array of strings. Replace the curly braces with parentheses:

# Use @() for an array, not @{} (which is a hashtable)
$names = @("name1@name.com","name2@name.com")

2. Fix the Folder Path Syntax Error

The error with $name:\Inbox happens because PowerShell interprets $name: as a drive identifier (like C: or D:), which isn't what you want here. To avoid this parsing issue, you have two reliable fixes:

Option 1: Use Subexpression to Construct the Path

Wrap the variable in a subexpression $($name) to tell PowerShell to fully resolve the variable before processing the rest of the path string:

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

Option 2: Fetch the Inbox Folder Identity Explicitly

For more reliability (especially if folder names vary), use Get-MailboxFolder to retrieve the exact inbox identity for each user:

foreach($name in $names){
 Write-Host "Creating rule for $name"
 # Get the inbox folder object for the user
 $inbox = Get-MailboxFolder -Identity "$name:\Inbox"
 # Use the folder's Identity property in the rule
 new-inboxrule -Name "MoveFromMailchimp" -Mailbox $name -MoveToFolder $inbox.Identity -From "senderEmailAddress" -StopProcessingRules $false
}

Bonus: Clean Up the Parameter Syntax

Note that -StopProcessingRules: $false has an unnecessary colon and space—you can simplify it to -StopProcessingRules $false (PowerShell parameter syntax doesn't require the colon here).

内容的提问来源于stack exchange,提问作者HubDamian

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 06:45:06