繁体   English   中英

无法连接azure自动化和在线交流

[英]unable to connect azure automation and exchange online

尝试使用自动化帐户中的服务帐户连接到 Exchange Online 时,我收到此错误。 我认为问题也可能是我的 $credential 变量没有传递到我的 $session 变量中,但我想不出任何原因会发生这种情况。


错误:

New-PSSession: [outlook.office365.com] Connecting to remote server outlook.office365.com failed with the following error message: Access is denied. 有关详细信息,请参阅 about_Remote_Troubleshooting 帮助主题。 在行:5 字符:12

  • $session = New-PSSession -ConfigurationName Microsoft.Exchange -Conne...
  •  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo: OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
    • fullyQualifiedErrorId:AccessDenied,PSSessionOpenFailed Import-PSSession:无法验证参数“会话”的参数。 参数是 null。 为参数提供一个有效值,然后再次尝试运行该命令。 在行:6 字符:42
  • 导入模块(导入 PSSession -Session $session -DisableNameCheckin...
  •  ~~~~~~~~

脚本:

参数([字符串] $Employee = "")$credential = Get-AutomationPSCredential -Name 'admin@crafthub.onmicrosoft.com' $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri 'https://outlook.office365。 com/powershell-liveid/' -Credential $credential -Authentication Basic -AllowRedirection Import-Module (Import-PSSession -Session $session -DisableNameChecking -AllowClobber) -Global $mailbox = Get-Mailbox -Identity $Employee Write-Output $mailbox


帮助将不胜感激

是的,看起来$credential变量没有传递到$session变量中。

在您的代码中,您已将 Azure 自动化凭证名称指定为“admin@crafthub.onmicrosoft.com”,因此请仔细检查您是否创建了具有确切名称“admin@crafthub.onmicrosoft.com”的 Azure 自动化凭证。

您可能已经知道,但只是让您知道在创建 Azure 自动化凭据时必须提供 Office 365 服务帐户的凭据。 To create Azure Automation credential, goto Azure Portal -> Your Azure Automation Account -> 'Credentials' tile -> Click on '+ Add a credential' -> Provide a name for Azure Automation credential under 'Name', provide Office 365 service account's在“用户名”下的名称,在“密码”和“确认密码”下提供 Office 365 服务帐户的密码 -> 单击“创建”。

然后,在代码的 Get-AutomationPSCredential 命令行中提供 Azure 自动化凭证的名称,即$credential = Get-AutomationPSCredential -Name '<Above_Provided_Azure_Automation_Credential_Name>'

如果您已经完成所有这些操作而没有任何问题,那么我建议您尝试最新的“Exchange Online PowerShell V2”方式,即导入“ExchangeOnlineManagement”Azure 自动化模块,如下所示,然后连接,使用Connect-ExchangeOnline cmdlet 而不是New -PSSession cmdlet。 稍后,当您尝试获取邮箱详细信息时,请使用Get-EXOMailbox cmdlet 而不是Get-Mailbox cmdlet。 有关 w.r.t 的更多信息,请参阅文档。

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM