技術文章 · IT 指令工具箱

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

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

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

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

演練值如何代入。以 LAB_ 開頭的代號代表合成測試值。命令或設定中的代號,請先一致代換成隔離測試環境的值。前綴代號依欄位規格填入前綴長度,需要位址型別的欄位請填入合法的合成位址。代換後再驗證設定語法與預期結果。

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

22 組範例Exchange OnlineExchangeOnlineManagement modulePowerShell 7/Windows PowerShell查核日期:2026-11-14
動手前:匯出結果可能含全公司信箱、代理人與群組成員。使用最小 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 $LabAdminUpn -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 -Identity $LabMailbox -Properties RecipientTypeDetails,EmailAddresses | Select-Object RecipientTypeDetails,EmailAddresses

依核准範圍選欄位。正式分享前移除地址;缺欄位時查 Properties 或 PropertySets。

搜尋所有收件者Exchange Online PowerShell

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

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

查 ProxyAddressesExchange Online PowerShell

Get-EXOMailbox user@LAB_DNS_NAME_5 -Properties EmailAddresses | Select-Object -ExpandProperty EmailAddresses

大寫 SMTP: 表示 primary address。

查看 Mailbox PermissionExchange Online PowerShell

Get-EXOMailboxPermission user@LAB_DNS_NAME_5 | Where-Object IsInherited -eq $false

FullAccess 和 SendAs 是不同權限。

查看 SendAs 權限Exchange Online PowerShell

Get-RecipientPermission user@LAB_DNS_NAME_5 | 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 含公司帳號資料,要限制存取與保存期限。

驗收與排錯

先確認租戶,再查一個合成收件者

比對 Get-ConnectionInformation 的連線、所屬租戶與角色。用已定義的 $LabMailbox 查看收件者類別、FullAccess、SendAs、SendOnBehalf 和 forwarding。這些是分開的權限與狀態。

若角色不足,只調整實際要驗收的最小範圍;離開後斷開該工作階段。完成權限變更以新工作階段實測允許、拒絕和正常寄件。

常見錯誤

  • 使用 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 或系統內建說明確認,再以當版官方文件為準。

查核資料

  1. Microsoft Exchange Online PowerShell 模組
  2. Microsoft Get-EXOMailbox
  3. Microsoft Get-EXOMailbox 欄位與命令
  4. Microsoft Exchange Online SMTP AUTH 設定

常見問題

Connect-ExchangeOnline 要關掉 MFA 嗎?

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

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

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

聯絡廷皓討論 看更多文章