技術文章 · IT 指令工具箱

Exchange Online PowerShell:連線、Mailbox、群組與權限查詢

整理 ExchangeOnlineManagement 安裝、Connect-ExchangeOnline、Get-EXOMailbox、收件者、群組、Mailbox Permission、Accepted Domain 與設定盤點。

作者 Steve Chen · 發布  · 約 10 分鐘閱讀

IT 指令工具箱 — 廷皓技術專欄插圖

Exchange Online 管理先從唯讀盤點開始。Get-EXO* cmdlet 適合大量查詢;實際新增 alias、改權限或變更 mail flow 前,先縮到單一測試物件並保留原值。

22 組範例Exchange OnlineExchangeOnlineManagement modulePowerShell 7/Windows PowerShell查核日期:2026-08-11
動手前:匯出結果可能含全公司信箱、代理人與群組成員。使用最小 RBAC 角色、MFA 或 app-only certificate,避免把密碼、token、certificate private key 放進腳本。

模組與連線

查看模組版本PowerShell

Get-InstalledModule ExchangeOnlineManagement -ErrorAction SilentlyContinue

沒有結果才需要安裝。

安裝目前使用者模組PowerShell

Install-Module ExchangeOnlineManagement -Scope CurrentUser

企業環境先確認 PSGallery、簽章與版本控管。

更新模組PowerShell

Update-Module ExchangeOnlineManagement

自動化主機不要未測試就升版。

互動式連線PowerShell

Connect-ExchangeOnline -UserPrincipalName [email protected] -ShowBanner:$false

使用具名管理帳號與 MFA。

查看目前連線PowerShell

Get-ConnectionInformation

確認 UserPrincipalName、State、TokenStatus 與 ConnectionUri。

登出並清除 sessionPowerShell

Disconnect-ExchangeOnline -Confirm:$false

腳本結束一定登出,避免殘留 session。

Mailbox 與收件者

列出信箱摘要Exchange Online PowerShell

Get-EXOMailbox -ResultSize Unlimited -Properties DisplayName,PrimarySmtpAddress,RecipientTypeDetails | Select-Object DisplayName,PrimarySmtpAddress,RecipientTypeDetails

大量 tenant 可分批與縮小 Properties。

查單一信箱Exchange Online PowerShell

Get-EXOMailbox [email protected] -Properties *

輸出前先挑需要欄位,避免洩漏不必要資訊。

搜尋所有收件者Exchange Online PowerShell

Get-EXORecipient -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress,RecipientType

可找 mailbox、group、contact、mail user 地址衝突。

查 ProxyAddressesExchange Online PowerShell

Get-EXOMailbox [email protected] -Properties EmailAddresses | Select-Object -ExpandProperty EmailAddresses

大寫 SMTP: 表示 primary address。

查看 Mailbox PermissionExchange Online PowerShell

Get-EXOMailboxPermission [email protected] | Where-Object IsInherited -eq $false

FullAccess 和 SendAs 是不同權限。

查看 SendAs 權限Exchange Online PowerShell

Get-RecipientPermission [email protected] | Where-Object Trustee -ne 'NT AUTHORITY\SELF'

SendOnBehalf 另看 GrantSendOnBehalfTo。

查看 mailbox forwardingExchange Online PowerShell

Get-EXOMailbox -ResultSize Unlimited -Properties ForwardingAddress,ForwardingSmtpAddress,DeliverToMailboxAndForward | Where-Object {$_.ForwardingAddress -or $_.ForwardingSmtpAddress}

外部自動轉寄需符合資安與 outbound spam policy。

群組、網域與組織設定

列出 Distribution GroupExchange Online PowerShell

Get-DistributionGroup -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress,GroupType

Microsoft 365 Group 另用 Get-UnifiedGroup。

查看群組成員Exchange Online PowerShell

Get-DistributionGroupMember -Identity 'All-Staff' -ResultSize Unlimited

Dynamic Distribution Group 沒有靜態 member 清單。

列出 Microsoft 365 GroupsExchange Online PowerShell

Get-UnifiedGroup -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress,AccessType

同時確認 owner 與外部寄件設定。

查看 Accepted DomainsExchange Online PowerShell

Get-AcceptedDomain | Format-Table Name,DomainName,DomainType,Default

Authoritative 與 InternalRelay 的 routing 行為不同。

查看 Inbound ConnectorsExchange Online PowerShell

Get-InboundConnector | Format-List Name,Enabled,ConnectorType,SenderDomains,SenderIPAddresses,RequireTls

IP、certificate 與 sender domain 必須和實際來源一致。

查看 Outbound ConnectorsExchange Online PowerShell

Get-OutboundConnector | Format-List Name,Enabled,ConnectorType,RecipientDomains,SmartHosts,TlsSettings

確認 smart host 與 TLS 要求。

列出 Mail Flow RulesExchange Online PowerShell

Get-TransportRule | Sort-Object Priority | Select-Object Name,State,Mode,Priority

先查 audit/test mode,再看是否有 stop processing。

查看組織 mail flow 設定Exchange Online PowerShell

Get-TransportConfig | Format-List SmtpClientAuthenticationDisabled,ExternalPostmasterAddress,MaxReceiveSize,MaxSendSize

個別 mailbox 或 policy 仍可能覆蓋部分設定。

匯出信箱盤點Exchange Online PowerShell

Get-EXOMailbox -ResultSize Unlimited -Properties DisplayName,PrimarySmtpAddress,RecipientTypeDetails | Select-Object DisplayName,PrimarySmtpAddress,RecipientTypeDetails | Export-Csv .\exo-mailboxes.csv -NoTypeInformation -Encoding utf8

CSV 含公司帳號資料,要限制存取與保存期限。

怎麼確認有做對

  • 每次連線確認 tenant 與管理帳號,結束後 Disconnect。
  • 變更前後用相同 Get 指令匯出並比對。
  • 用實際寄送、委派登入與群組收件驗證,不只看 cmdlet 成功。

常見錯誤

  • 使用 Global Admin 跑所有日常查詢。
  • 把舊 Remote PowerShell session 範例和新版 REST-backed cmdlet 混用。
  • 只查 FullAccess,漏掉 SendAs、SendOnBehalf 與 forwarding。
  • 匯出全 tenant 資料後丟在公開分享資料夾。

常見問題

Connect-ExchangeOnline 要關掉 MFA 嗎?

不需要。互動管理應保留 MFA;無人值守腳本改用 app-only certificate 或 managed identity,不要退回帳密硬寫。

Get-Mailbox 和 Get-EXOMailbox 要用哪個?

Exchange Online 大量查詢通常優先 Get-EXOMailbox 並明確指定 Properties;特定舊參數仍可能要 Get-Mailbox,依當版文件與模組支援。

延伸閱讀

版本與官方文件

參數會隨工具版本與作業系統實作改變。正式環境先用 --help、-h 或系統內建說明確認,再以當版官方文件為準。

常見問題

Connect-ExchangeOnline 要關掉 MFA 嗎?

不需要。互動管理應保留 MFA;無人值守腳本改用 app-only certificate 或 managed identity,不要退回帳密硬寫。

Get-Mailbox 和 Get-EXOMailbox 要用哪個?

Exchange Online 大量查詢通常優先 Get-EXOMailbox 並明確指定 Properties;特定舊參數仍可能要 Get-Mailbox,依當版文件與模組支援。

聯絡廷皓討論 看更多文章