如果您將內建安全性附加元件用於內部部署信箱,您可以使用本文中的指令碼來檢視 (,並經過修改,) 您管理的不同組織中的組態設定進行設定。
若要使用內部部署信箱的內建安全性附加元件在多個組織中執行指令碼或 Cmdlet
如果您尚未安裝,請安裝 Exchange Online PowerShell 模組。
使用 Excel 或其他試算表應用程式Microsoft建立包含下列詳細資料的 .csv 檔案:
- 使用者名稱資料欄位:您用來連線到雲端 (的帳戶,例如
admin@contoso.onmicrosoft.com) 。 -
Cmdlet 資料欄位:例如要
Get-AcceptedDomainGet-AcceptedDomain | Format-Table Name執行 (或) 的 Cmdlet 或命令。
.csv 檔案看起來像這樣:
UserName,Cmdlet admin@contoso.onmicrosoft.com,Get-AcceptedDomain | Format-Table Name admin@fabrikam.onmicrosoft.com,Get-AcceptedDomain | Format-Table Name- 使用者名稱資料欄位:您用來連線到雲端 (的帳戶,例如
將 .csv 檔案儲存在容易找到的位置 (例如 c:\scripts\inputfile.csv) 。
將 RunCmdletOnMultipleTenants.ps1 指令碼複製到記事本或其他文字編輯器,然後將檔案儲存到容易找到的位置 (例如 c:\scripts) 。
使用下列語法執行指令碼:
& "<file path>\RunCmdletOnMultipleTenants.ps1" "<file path>\inputfile.csv"以下為範例:
& "c:\scripts\RunCmdletOnMultipleTenants.ps1" "c:\scripts\inputfile.csv"指令碼會登入每個雲端組織,並在其中執行。
RunCmdletOnMultipleTenants.ps1
# This script runs Windows PowerShell cmdlets on multiple tenants.
#
# Usage: RunCmdletOnMultipleTenants.ps1 inputfile.csv
#
# .csv input file sample:
#
# UserName,Cmdlet
# admin@contoso.onmicrosoft.com,Get-AcceptedDomain | FT Name
# admin@fabrikam.onmicrosoft.com,Get-AcceptedDomain | FT Name
# Get the .csv file name as an argument to this script.
$FilePath = $args[0]
# Import the UserName and Cmdlet values from the .csv file.
$CompanyList = Import-CSV $FilePath
# Load the Exchange Online PowerShell module
Import-Module ExchangeOnlineManagement
# Loop through each entry from the .csv file.
ForEach ($Company in $CompanyList) {
# Get the current entry's UserName.
$UserName = $Company.UserName
# Get the current entry's Cmdlet.
$Cmdlet = $Company.Cmdlet
# Connect to Exchange Online PowerShell by using the current entry's UserName. Prompt for the password.
Connect-ExchangeOnline -UserPrincipalName $UserName
# Here's where the script to be run on the tenant goes.
# In this example, the cmdlet in the .csv file runs.
Invoke-Expression $Cmdlet
# End the current PowerShell session.
Disconnect-ExchangeOnline -Confirm:$false
}