【问题标题】:Connect-ExchangeOnline UnAuthorizedConnect-ExchangeOnline 未经授权
【发布时间】:2022-11-07 19:58:22
【问题描述】:

我正在努力更新我们的 PowerShell 脚本以使用更安全的连接方法。当我尝试时,我收到一条错误消息,显示“未经授权”

PS X:> Connect-ExchangeOnline -AppId $clientId -CertificateThumbprint $thumbPrint -Organization $organization UnAuthorized 在 C:\程序 Files\WindowsPowerShell\Modules\ExchangeOnlineManagement\3.0.0\netFramework\ExchangeOnlineManagement.psm1:730 char:21

  • 抛出$_.Exception;
  • CategoryInfo : OperationStopped: (:) [], UnauthorizedAccessException
    • FullyQualifiedErrorId:未经授权

我在以下屏幕截图中突出显示的内容是我应该用于组织参数的吗? [剪辑]

如何修复未经授权的错误?

谢谢

【问题讨论】:

  • 首先,是的,Organization 参数使用您的租户名称。其次,我们没有足够的支持信息来为您解决此问题。查看this documentation 的要求。第三,我不确定您是否要在图像中包含识别信息(租户名称、租户 ID、组织)。如果我不得不猜测,您的应用程序缺少权限或角色之一

标签: powershell azure-active-directory


【解决方案1】:

我同意@scottwtang, 你会得到未经授权如果您的应用程序没有所需的角色和权限,则会出错。

我试图在我的环境中重现相同的结果并得到以下结果:

我用了下面的脚本从您之前的问题生成证书:

$CN = "GraphApp" 
$cert=New-SelfSignedCertificate -Subject "CN=$CN" -CertStoreLocation "Cert:CurrentUserMy" -KeyExportPolicy Exportable -KeySpec Signature -NotAfter (Get-Date).AddYears(5)
$Thumbprint = $Cert.Thumbprint
Get-ChildItem Cert:CurrentUsermy$Thumbprint | Export-Certificate -FilePath $env:USERPROFILEDownloadsGraphApp.cer
Write-Output "$Thumbprint <- Copy/paste this (save it)"

输出:

现在我上传了这个证书到 Azure AD 应用程序,如下所示:

为了$organization参数,您需要传递您的域名。你可以在这里找到:

转到 Azure 门户 -> Azure Active Directory -> 概述 -> 主域

当我运行以下脚本进行连接时在线交流, 我有Access denied像这样的错误:

$clientId="47xxxd8-8x2x-4xxx-bxx7-30cxxxxx8"
$thumbPrint="E4A0F6C6B85EBFxxxxxCD91B5803F88E5"
$organization="xxxxxxxx.onmicrosoft.com"

Connect-ExchangeOnline -AppId $clientId -CertificateThumbprint $thumbPrint -Organization $organization

输出:

解决错误,您需要添加API permissionDirectory对您的应用程序的作用:

确保授予管理员同意添加权限如下:

现在我添加了交易所管理员我的应用程序的角色如下:

转到 Azure 门户 -> Azure Active Directory -> 角色和管理员 -> Exchange 管理员 -> 添加分配

可能需要一会儿成功分配角色如下:

现在我连接到在线交流通过再次运行脚本并运行示例命令Get-EXOMailbox -PropertySets Archive 来验证它并得到回复成功如下:

$clientId="47xxxd8-8x2x-4xxx-bxx7-30cxxxxx8"
$thumbPrint="E4A0F6C6B85EBFxxxxxCD91B5803F88E5"
$organization="xxxxxxxx.onmicrosoft.com"

Connect-ExchangeOnline -AppId $clientId -CertificateThumbprint $thumbPrint -Organization $organization

输出:

因此,请确保分配 required角色权限让您的应用程序修复错误。

【讨论】:

    【解决方案2】:

    不幸的是 Exchange.ManageAsApp 不再出现在 API 权限中

    【讨论】:

      猜你喜欢
      • 2018-06-15
      • 2011-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 2011-03-06
      相关资源
      最近更新 更多