【问题标题】:How to use Connect ExchangeOnline -DelegatedOrganization如何使用 Connect ExchangeOnline -DelegatedOrganization
【发布时间】:2023-04-06 15:27:01
【问题描述】:

我正在尝试构建一个使用委派管理员权限的脚本。而我的工作就是这个。

$ConnectionUri = "https://ps.outlook.com/powershell-liveid?DelegatedOrg=$TenantDefaultDomainName"
    
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $ConnectionUri -Credential $Office365Credentials -Authentication Basic -AllowRedirection 
Import-PSSession $Session -AllowClobber

这很好,连接也很好,但我的印象是,这是旧的做法,因为一些 cmdlet 根本不适用于委派。例如,我想获取用户日历的名称并尝试使用

Get-MailboxFolderStatistics -Identity $user -FolderScope Calendar

但是我在代理命令上收到一个错误,说委派用户应该为空。因此,我想尝试使用新的 cmdlet,但几乎找不到任何有关委派的信息,请参考此处:https://docs.microsoft.com/en-us/powershell/module/exchange/connect-exchangeonline?view=exchange-ps

我想出了这个语法,但它根本不起作用。

Connect-ExchangeOnline -DelegatedOrganization $TenantDefaultDomainName -Credential $MyOffice365PartnerCredentials

这是我遇到的错误。

New-ExoPSSession : One or more errors occurred.
At C:\Program Files\WindowsPowerShell\Modules\ExchangeOnlineManagement\2.0.4\netFramework\ExchangeOnlineManagement.psm1:475 char
:30
+ ... PSSession = New-ExoPSSession -ExchangeEnvironmentName $ExchangeEnviro ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-ExoPSSession], AggregateException
    + FullyQualifiedErrorId : System.AggregateException,Microsoft.Exchange.Management.ExoPowershellSnapin.NewExoPSSession

【问题讨论】:

    标签: powershell


    【解决方案1】:

    我在 GitHub 上打开了一个问题,因为这不是预期的行为,@chrisda 用回复来救我

    “这是在黑暗中拍摄,但请尝试将 -UserPrincipalName 参数与 Connect-ExchangeOnline 一起使用:”

    Connect-ExchangeOnline -DelegatedOrganization $TenantDefaultDomainName -UserPrincipalName <MyOffice365PartnerUPN>
    

    神秘的是,在使用 connect-exchangeonline 时,您可以使用所有正常命令,例如 get-mailboxfolderstatistics,这些命令不适用于我在问题中首先提到的旧合作伙伴方法。希望这对我以外的人有所帮助,在 MS 文档或互联网上我能找到的任何其他地方都没有任何参考。

    参考:https://github.com/MicrosoftDocs/office-docs-powershell/issues/7458

    【讨论】:

    • "Add -UserPrincipalName" 技巧完成了另一个权限错误的工作,谢谢
    【解决方案2】:

    我在帐户上启用 MFA 时遇到此错误。

    【讨论】:

      猜你喜欢
      • 2022-11-07
      • 2021-08-12
      • 1970-01-01
      • 2022-10-31
      • 2020-10-10
      • 2023-04-06
      • 2020-12-30
      • 2018-04-17
      • 2016-02-28
      相关资源
      最近更新 更多