首页 > 解决方案 > 使用访问令牌通过 Powershell 连接到 Exchange Online

问题描述

我从 Azure AD 获得了访问令牌和刷新令牌。我需要使用访问令牌/刷新令牌从 powershell 连接到各种 O365 服务。有人可以指导我如何继续在线连接到交换服务器。

有没有其他方法可以使用现代身份验证在线连接到交换服务器。我正在使用 ExchangeOnlineManagement 2.0.3 版本。我根据下面列出的博客的建议使用了下面的代码片段。我收到类似“密码长度超过 256”的错误。

https://o365reports.com/2020/07/04/modern-auth-and-unattended-scripts-in-exchange-online-powershell-v2/

https://www.michev.info/Blog/Post/1771/hacking-your-way-around-modern-authentication-and-the-powershell-modules-for-office-365

我们需要自动化该过程,但无法使用访问令牌连接到交易所。

$AccessToken = <access-token-value>
$Authorization = "Bearer {0} " -f $AccessToken
$Password = ConvertTo-SecureString -AsPlainText $Authorization -Force
$UserCredential = New-Object System.Management.Automation.PSCredential("<upn-value>", $Password)
Connect-ExchangeOnline -Credential $UserCredential -ShowProgress $true

错误消息:我收到密码长度超过 256 个字符的错误。

标签: azurepowershellauthenticationexchange-server

解决方案


抱歉耽搁了。

我理解你的要求。我知道使用New-PSSession基本身份验证很快就会被弃用,因此您正在寻找替代方案。

但目前不支持使用访问令牌连接到 Exchange Online,因为AADSTS50052: The password entered exceeds the maximum length of '256'.. 我不认为你需要担心它。届时,微软应该能够覆盖 V1 模块所具有的所有功能。

在这里看到一个类似的问题。


推荐阅读