スタンドアロン EOP 設定を複数のテナントに適用するスクリプトのサンプル
この記事のサンプル PowerShell スクリプトは、複数のスタンドアロン Exchange Online Protection (EOP) テナントを管理する管理者向けです。 管理者は、この記事のスクリプトを使用して、構成設定を表示したり、複数のスタンドアロン EOP テナントに適用したりできます。
複数のテナントでスクリプトまたはコマンドレットを実行するには
まだインストールしていない場合は、Exchange Online PowerShell モジュールをインストールします。
スプレッドシート アプリ (Excel など) を使用して、次の詳細を含む.csv ファイルを作成します。
- UserName 列: 接続に使用するアカウント (例:
admin@contoso.onmicrosoft.com
)。 - コマンドレット列: 実行するコマンドレットまたはコマンド (または など
Get-AcceptedDomain
Get-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
- UserName 列: 接続に使用するアカウント (例:
.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 EOP 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
}