連線到安全性與合規性中心 PowerShell
Exchange Online PowerShell V2 模組(縮寫為 EXO V2 模組)使用新式驗證,可與多重要素驗證(MFA)搭配使用,以連線到 Microsoft 365 中的所有 Exchange 相關 PowerShell 環境: Exchange Online PowerShell、安全性與合規性 PowerShell,以及獨立 Exchange Online Protection (EOP) PowerShell。 如需 EXO V2 模組的詳細資訊,請參閱Exchange Online PowerShell V2 模組相關資訊。
本文包含如何使用 EXO V2 模組 (搭配或不搭配 MFA),連線到安全性與合規性中心 PowerShell 的指示。
若要使用 終將被棄用的較不安全的舊版遠端 PowerShell 連線指示,請參閱 基本驗證-連線到安全性與合規性中心 PowerShell。
如需使用較舊版 Exchange Online 遠端 PowerShell 模組,透過多重要素驗證,連線至安全性與合規性中心 PowerShell,請參閱V1模組 - 使用多重要素驗證連線至安全性與合規性中心 PowerShell。 請注意,此舊版模組終將失效。
開始之前有哪些須知?
安裝和使用 EXO V2 模組的需求,請參閱 安裝及維護 EXO V2 模組。 本文中的其餘指示皆假設您已安裝該模組。
連線後,您有權或無權存取的 cmdlet 和參數由角色型存取控制 (RBAC) 控制。 如需詳細資訊,請參閱安全性與合規性中心中的權限。
使用 MFA 和新式驗證連線至安全性與合規性 PowerShell
如果您的帳戶使用多重要素驗證,請使用本節所述的步驟。 否則,請跳至 使用新式驗證,連線到安全性與合規性中心 PowerShell 一節。
在 Windows PowerShell 視窗中,執行下列命令來載入 EXO V2 模組:
Import-Module ExchangeOnlineManagement
附註:如果您已 安裝 EXO V2 模組,則先前的命令可如其編寫方式運作。
您需要執行的最後一個命令會使用以下語法:
Connect-IPPSSession -UserPrincipalName <UPN> [-ConnectionUri <URL>] [-PSSessionOption $ProxyOptions]
- <UPN> 是以使用者主體名稱格式(例如
navin@contoso.com
)表示的您的帳戶。 - 所需的 ConnectionUri 值取決於您 Microsoft 365 組織的特性。 如需詳細資訊,請參閱 Connect-IPPSSession 中的參數描述。
- 當您使用 UserPrincipalName 參數時,您不需要在原本需要的環境中使用 AzureADAuthorizationEndpointUri 參數。
- 如果您在 Proxy 伺服器背後,請先執行下列命令:
$ProxyOptions = New-PSSessionOption -ProxyAccessType <Value>
,其中的 <Value> 是IEConfig
、WinHttpConfig
或AutoDetect
。 然後,使用 PSSessionOption 參數搭配值$ProxyOptions
。 如需詳細資訊,請參閱 New-PSSessionOption。
此範例會連線至 Microsoft 365 或 Microsoft 365 GCC 組織中的安全性與合規性中心 PowerShell。
Connect-IPPSSession -UserPrincipalName navin@contoso.com
此範例會連線至 Office 365 德國組織中的安全性與合規性中心。
Connect-IPPSSession -UserPrincipalName lukas@fabrikam.de -ConnectionUri https://ps.compliance.protection.outlook.de/PowerShell-LiveID
此範例會連線至 Microsoft GCC High 組織中的安全性與合規性中心。
Connect-IPPSSession -UserPrincipalName -ConnectionUri https://ps.compliance.protection.office365.us/powershell-liveid/
此範例會連線至 Microsoft 365 DoD 組織中的安全性與合規性中心。
Connect-IPPSSession -UserPrincipalName -ConnectionUri https://l5.ps.compliance.protection.office365.us/powershell-liveid/
- <UPN> 是以使用者主體名稱格式(例如
如需詳細的語法和參數資訊,請參閱 Connect-IPPSSession。
注意
完成時,請務必中斷遠端 PowerShell 工作階段連線。如果未先中斷工作階段連線即關閉 Windows PowerShell 視窗,您可能會用完您可以使用的所有遠端 PowerShell 工作階段,而需要等待這些工作階段到期。若要中斷遠端 PowerShell 工作階段連線,請執行下列命令。
Disconnect-ExchangeOnline
使用新式驗證連線至安全性與合規性中心 PowerShell
如果您的帳戶未使用多重要素驗證,請使用本節所述的步驟。
在 Windows PowerShell 視窗中,執行下列命令來載入 EXO V2 模組:
Import-Module ExchangeOnlineManagement
附註:如果您已 安裝 EXO V2 模組,則先前的命令可如其編寫方式運作。
執行下列命令:
注意
執行 Connect-IPPSSession 命令後,在提示輸入使用者名稱和密碼的下一步,您可以跳過此步驟並省略 Credential 參數。 如果在下一步中省略 Credential 參數並包含 UserPrincipalName 參數,則只有在執行 Connect ippsession 命令後才會提示您輸入密碼。
$UserCredential = Get-Credential
在隨即出現的 [Windows PowerShell 認證要求] 對話方塊中,輸入您的公司或學校帳戶和密碼,然後按一下 [確定]。
附註:Connect-IPPSSession 命令完成後,
$UserCredential
中的密碼將清空。您需要執行的命令會使用下列語法:
Connect-IPPSSession [-Credential $UserCredential] [-ConnectionUri <URL>] [-AzureADAuthorizationEndpointUri <URL>] [-PSSessionOption $ProxyOptions]
- 所需的 ConnectionUri 和 AzureADAuthorizationEndPointUri 值,取決於您的 Microsoft 365 組織特性。 如需詳細資訊,請參閱 Connect-IPPSSession 中的參數描述。
- 如果您在 Proxy 伺服器後面,請將 New-PSSessionOption cmdlet 的輸出儲存在變數中 (例如,
$ProxyOptions = New-PSSessionOption -ProxyAccessType <Value> [-ProxyAuthentication <Value>] [-ProxyCredential <Value>]
)。 然後,使用變數 ($ProxyOptions
) 做為 PSSessionOption 參數的值。
此範例會連線至 Microsoft 365 或 Microsoft 365 GCC 組織中的安全性與合規性中心 PowerShell。
Connect-IPPSSession -Credential $UserCredential
此範例會連線至 Office 365 德國組織中的安全性與合規性中心。
Connect-IPPSSession -Credential $UserCredential -ConnectionUri https://ps.compliance.protection.outlook.de/ -AzureADAuthorizationEndpointUri https://login.microsoftonline.de/common
此範例會連線至 Microsoft GCC High 組織中的安全性與合規性中心。
Connect-IPPSSession -Credential $UserCredential -ConnectionUri https://ps.compliance.protection.office365.us/powershell-liveid/ -AzureADAuthorizationEndpointUri https://login.microsoftonline.us/common
此範例會連線至 Microsoft 365 DoD 組織中的安全性與合規性中心。
Connect-IPPSSession -Credential $UserCredential -ConnectionUri https://l5.ps.compliance.protection.office365.us/powershell-liveid/ -AzureADAuthorizationEndpointUri https://login.microsoftonline.us/common
如需詳細的語法和參數資訊,請參閱 Connect-IPPSSession。
注意
完成時,請務必中斷遠端 PowerShell 工作階段連線。 如果未先中斷工作階段連線即關閉 Windows PowerShell 視窗,您可能會用完您可以使用的所有遠端 PowerShell 工作階段,而需要等待這些工作階段到期。 若要中斷遠端 PowerShell 工作階段的連線,請執行下列命令:
Disconnect-ExchangeOnline
如何知道這是否正常運作?
安全性與合規性中心 Cmdlet 就會匯入到本機 Windows PowerShell 工作階段中,並透過進度列進行追蹤。 如果您未收到任何錯誤,便已順利連線。 快速測試方式就是執行安全性與合規性中心 Cmdlet,例如 Install-UnifiedCompliancePrerequisite,並查看結果。
如果出現錯誤,請檢查下列需求:
密碼錯誤是常見的問題。 再次執行這三個步驟,並特別留意您使用的使用者名稱和密碼。
為防止拒絕服務 (DoS) 的攻擊,您最多只能為 [安全性與合規性中心] 開啟五個遠端 PowerShell 連線。
用來連線的帳戶必須能夠使用遠端 PowerShell。 如需詳細資訊,請參閱啟用或停用 Exchange Online 的封存權。
必須在本機電腦與 Microsoft 365 之間開啟 TCP 連接埠 80 流量。 該連接埠可能已開啟,但必須考量您的組織是否有限制性網際網路存取原則。
如果您的用戶端 IP 位址在連線要求其間變更,則您可能會無法連線。 如果您的組織使用的來源網路位址轉譯 (SNAT) 集區包含多個 IP 位址,則可能會發生次情況。 連線錯誤看起來會像這樣:
具有 ShellId <ID> 的 Windows Remote Shell 要求失敗,因為在伺服器上找不到 Shell。 可能的原因如下:指定的 ShellId 不正確,或者伺服器上已不存在 Shell。 提供正確的 ShellId 或建立新的 Shell,然後重試操作。
若要修正此問題,請使用 SNAT 集區 (其中包含單一 IP 位址),或讓安全性與合規性 PowerShell 端點的連線強制使用特定的 IP 位址。