1

我有一个 MS 提供的 powershell 脚本,我已经对其进行了编辑。真正的形式 MS 提供了一个使用旧代码的脚本。由于我们启用了 MFA,我不能再使用 Get-Credential 进行身份验证,因为我们使用的是 Modern Auth 而不是 Basic。如何编辑代码以支持 MFA?我们不使用 Auzer MFA,我们使用 Duo。

旧代码:

$adminCredential = Get-Credential

    Write-Output "Connecting to Exchange Online Remote Powershell Service"
    $ExoSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $adminCredential -Authentication Basic -AllowRedirection
    if ($null -ne $ExoSession) { 
        Import-PSSession $ExoSession -AllowClobber
    } else {
        Write-Output "  No EXO service set up for this account"
    }

    Write-Output "Connecting to EOP Powershell Service"
    $EopSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $adminCredential -Authentication Basic -AllowRedirection
    if ($null -ne $EopSession) { 
        Import-PSSession $EopSession -AllowClobber
    } else {
        Write-Output "  No EOP service set up for this account"
    }

新命令应该是 Connect-IPPSSession 而不是 New-PSSession 但我必须以某种方式更改 Get-Credential 以传递凭据和 MFA 我只是不知道该怎么做。

4

4 回答 4

1

如果你想使用 OAuth 认证,你需要有 Access Token

一旦应用程序有了访问令牌,它就可以使用该令牌通过 API 访问用户的帐户,仅限于访问范围,直到令牌过期或被撤销。

这是一个使用 curl 的 API 请求示例。请注意,它包括访问令牌:

curl -X POST -H "Authorization: Bearer ACCESS_TOKEN""https://api.digitalocean.com/v2/$OBJECT"

您可以针对 OAuth 进行身份验证,请参阅以下链接:

使用 PowerShell 针对 OAuth 进行身份验证

于 2018-10-10T03:27:49.723 回答
1

完全披露,我和我支持的任何客户都没有使用 Duo。

话虽如此,MS 中没有关于使用 DUO 作为 O365 源的 PowerShell 和 MFA 的文档。

根据 MS...

使用多重身份验证 (MFA) 和 PowerShell 连接到 Office 365 服务

使用多重身份验证连接到 Exchange Online PowerShell

您不能使用 Exchange Online 远程 PowerShell 模块在同一会话(窗口)中连接到 Exchange Online PowerShell 和安全与合规中心 PowerShell。您需要使用 Exchange Online 远程 PowerShell 模块的单独会话。

如果要使用多重身份验证 (MFA)连接到 Exchange Online PowerShell,则不能使用连接到 Exchange Online PowerShell 中的说明

https://docs.microsoft.com/en-us/powershell/exchange/exchange-online/connect-to-exchange-online-powershell/connect-to-exchange-online-powershell?view=exchange-ps

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

使用远程 PowerShell 连接到 Exchange Online。

MFA 要求您安装 Exchange Online 远程 PowerShell 模块,并使用 Connect-EXOPSSession cmdlet 进行连接。

Connect-EXOPSSession -UserPrincipalName <UPN> [-ConnectionUri <ConnectionUri> -AzureADAuthorizationEndPointUri <AzureADUri>]

使用 Office 365 和 PowerShell 进行多重身份验证 (MFA) 设置和最终用户体验

另请参阅,如果您还没有。

如何更改发送到 Duo 的用户名格式?

于 2018-10-10T03:38:08.747 回答
0

阅读答案后,我意识到我没有以足够详细的方式来组织我的问题来获得我需要的答案。我将保留问题并将其中一个答案标记为答案,因为它确实回答了我提出的问题,而不是我希望学习的问题。

于 2018-10-10T13:50:35.473 回答
0

The Connect-ExchangeOnline supports login with 2FA. You can run it as is without any arguments.

于 2020-07-15T08:50:26.437 回答