簡體   English   中英

如何使用 Connect ExchangeOnline -DelegatedOrganization

[英]How to use Connect ExchangeOnline -DelegatedOrganization

我正在嘗試構建一個使用委派管理員權限的腳本。 我的工作就是這個。

$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

但是我在代理命令上收到一個錯誤,說委派用戶應該是 null。 因此,我想嘗試使用新的 cmdlet,但幾乎找不到任何有關委派的信息,請參考此處: https://docs.microsoft.com/en-us/powershell/module/exchange/connect-exchangeonline?view=交換-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

我在 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

當帳戶啟用 MFA 時出現此錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM