连接到租户的Powershell Office 365委派的管理员问题

时间:2018-10-06 15:06:19

标签: powershell connection office365

我已经阅读了Microsoft的文档以及许多示例,但是由于某些原因,使用我们的admin privs连接到租户将无法连接:

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell-liveid?DelegatedOrg=xxxxx.onmicrosoft.com -Credential $UserCredential -Authentication Basic –AllowRedirection

我也尝试过将域名替换为outlook.office365.com

返回的错误是:

  

New-PSSession:[ps.outlook.com]处理来自远程服务器的数据   ps.outlook.com失败,并显示以下错误消息:   [AuthZRequestId = 477bd052-617e-4e8c-aee9-dxxxxxxxx] [FailureCategory = AuthZ-CmdletAccessDeniedException]   无法执行该操作,因为   'xxxxx.onmicrosoft.com \ xxxxxxadmin@xxxxx.onmicrosoft.com'不能为   找到了。有关更多信息,请参见about_Remote_Troubleshooting帮助   主题。

我确保指定的管理员帐户为:

  • 全局管理员
  • 对您支持的公司的管理权限:是/完全管理员

我还尝试过搜索该错误,而不是大量信息。同样,该站点:https://gcits.com/knowledge-base/也提供了一些示例,使用这些示例会导致基本相同的挂断。

但是我可以连接并发出“ $ customers = Get-MsolPartnerContract -All”并查看所有租户。

有什么想法吗?

** UPDATE **代码如下所示(根据要求)。再次感谢!

$credential = Get-Credential
Connect-MsolService -Credential $credential
$customers = Get-MsolPartnerContract -All
Write-Host "Found $($customers.Count) customers for $((Get-MsolCompanyInformation).displayname)."

foreach ($customer in $customers) {

    Write-Host "Connecting to: $($customer.name)" -ForegroundColor Yellow
    $InitialDomain = Get-MsolDomain -TenantId $customer.TenantId | Where-Object {$_.IsInitial}


    $DelegatedOrgURL = "https://ps.outlook.com/powershell-liveid?DelegatedOrg=" + $InitialDomain.Name
    $EXODS = New-PSSession -ConnectionUri $DelegatedOrgURL -Credential $credential -Authentication Basic -ConfigurationName Microsoft.Exchange -AllowRedirection
    Import-PSSession $EXODS -CommandName Get-CASMailbox, Set-CasMailbox, Get-Casmailboxplan, set-casmailboxplan
     

1 个答案:

答案 0 :(得分:1)

我找到了解决方法

  • 这不适用于MFA帐户
  • 如果创建新帐户,则必须花一些时间才能使用。几天后,我使用了相同的委派管理员帐户,现在可以正常使用了。我不得不假设“某些事情”需要一段时间才能使权限生效。

感谢大家的帮助。