我已经尝试了几种变体(下面显示了全部3种)。使用此代码,如果我为-UserPrincipalName
指定一个值,则窗体将迅速弹出并消失,速度足够快,仅显示窗体边框。如果我没有为-UserPrincipalName
指定值,则会打开相同的表格,并要求我使用我的电子邮件地址登录。我尝试的第三个选项是使用-Credential
和一个凭据对象,但出现错误:
“ New-ExoPSSession:missing_federation_metadata_url:联盟用户缺少联合身份验证元数据网址。此用户类型为 不支持。” 。
我的最终目标是在不弹出表单的情况下进行身份验证,这样我就可以运行带有计划任务的一些代码,由于表单和交互模式,该任务现在不起作用。我可以使用信用,无需MFA,并且需要取消此表格 不知何故。
如何在不显示此表单的情况下连接到Exchange Online?有没有办法使用New-PSsession
或Import-PSsession
,或者将New-ExoPSSession
包裹起来以防止打开表单?
(此外,我们需要添加“ exchange-online”标签,我没有足够的声誉来做到这一点)
[string] $ConnectionUri = "https://outlook.office365.com/PowerShell-LiveId"
[string] $AzureADAuthorizationEndpointUri = 'https://login.windows.net/common'
[System.Management.Automation.Remoting.PSSessionOption] $PSSessionOption = $null
[switch] $BypassMailboxAnchoring = $false
[string] $DelegatedOrganization = ''
$PSSession = New-ExoPSSession -UserPrincipalName "xxx@xxx.xxx" -ConnectionUri $ConnectionUri -AzureADAuthorizationEndpointUri $AzureADAuthorizationEndpointUri -PSSessionOption $PSSessionOption -BypassMailboxAnchoring:$BypassMailboxAnchoring -DelegatedOrg $DelegatedOrganization
$PSSession = New-ExoPSSession -ConnectionUri $ConnectionUri -AzureADAuthorizationEndpointUri $AzureADAuthorizationEndpointUri -PSSessionOption $PSSessionOption -BypassMailboxAnchoring:$BypassMailboxAnchoring -DelegatedOrg $DelegatedOrganization
$user = "xxx@xxx.xxx";
$password = ConvertTo-SecureString "xxxx" -AsPlainText -Force;
$creds = New-Object System.Management.Automation.PSCredential -ArgumentList ($user, $password)
$PSSession = New-ExoPSSession -UserPrincipalName "xxx@xxx.xxx" -ConnectionUri $ConnectionUri -AzureADAuthorizationEndpointUri $AzureADAuthorizationEndpointUri -Credential $creds -PSSessionOption $PSSessionOption -BypassMailboxAnchoring:$BypassMailboxAnchoring -DelegatedOrg $DelegatedOrganization