![](/img/trans.png)
[英]How do I connect to Exchange and SharePoint PNP using Certificates from Azure KeyVault or Azure Automation
[英]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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~
脚本:
参数([字符串] $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.