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

PowerShell检查Outlook日历权限报错:指定邮箱不存在,如何修正?

解决PowerShell获取Outlook日历权限时的身份识别错误

问题场景

尝试编写以下PowerShell代码检查Outlook日历权限:

$Usermailbox = Read-Host "Please enter the mailbox whose permissions you want to see"
Get-MailboxFolderPermission -Identity "$Usermailbox :\calendar"

执行时出现错误:

Get-MailboxFolderPermission: xxxx|Microsoft.Exchange.Configuration.Tasks.ManagementObjectNotFoundException|The specified mailbox Identity:“xxx ” doesn’t exist.

问题根源是字符串拼接错误,代码将$Usermailbox :\calendar错误识别为包含多余空格的身份字符串,导致Exchange无法找到对应邮箱。

修正方案

正确的拼接方式需要明确变量边界,同时移除多余空格,有以下几种写法:

  1. 使用花括号包裹变量,明确变量范围:
$Usermailbox = Read-Host "Please enter the mailbox whose permissions you want to see"
Get-MailboxFolderPermission -Identity "${Usermailbox}:\calendar"
  1. 直接移除变量后的空格,PowerShell会自动解析变量:
$Usermailbox = Read-Host "Please enter the mailbox whose permissions you want to see"
Get-MailboxFolderPermission -Identity "$Usermailbox:\calendar"
  1. 使用字符串连接运算符+拼接:
$Usermailbox = Read-Host "Please enter the mailbox whose permissions you want to see"
Get-MailboxFolderPermission -Identity ($Usermailbox + ":\calendar")

说明

原代码中"$Usermailbox :\calendar"的问题在于变量后多了一个空格,导致生成的身份字符串格式为"邮箱名 :\calendar",Exchange会把包含空格的部分当成邮箱名称去查找,自然找不到对应对象。通过明确变量边界或移除多余空格,就能生成正确的身份格式"邮箱名:\calendar",让Exchange正确识别邮箱和日历文件夹。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 20:25:26