如果你使用內建的安全外掛(Add-in Security Addon)來管理本地郵箱,你可以使用本文中的腳本查看 (,並修改後,在你管理的不同組織中配置) 設定。
在多個組織中執行腳本或指令碼,並使用內建的安全外掛程式來處理本地郵箱
如果你還沒安裝,請安裝 Exchange Online PowerShell 模組。
使用 Excel 或其他試算表應用程式Microsoft建立包含以下細節的 .csv 檔案:
-
使用者名稱 欄位:例如你用來連接雲端 (的帳號,例如)
admin@contoso.onmicrosoft.com。 -
Cmdlet 欄位:例如,執行 (
Get-AcceptedDomainGet-AcceptedDomain | Format-Table Name或) 的指令或指令。
.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
}