スタンドアロン EOP 設定を複数のテナントに適用するスクリプトのサンプル

この記事の PowerShell スクリプトのサンプルは、複数のスタンドアロン ドメイン (EOP) テナントExchange Online Protection管理者向けです。 管理者は、この記事のスクリプトを使用して、複数のスタンドアロン EOP テナントに構成設定を表示および/または適用できます。

複数のテナントでスクリプトまたはコマンドレットを実行するには

  1. まだインストールしていない場合は、V2 モジュールExchange Onlineインストールします

  2. スプレッドシート アプリ (たとえば、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
    
  3. ファイルを.csv簡単に見つけることができる場所に保存します (たとえば、c:\scripts\inputfile.csv)。

  4. RunCmdletOnMultipleTenants.ps1スクリプトメモ帳にコピーし、ファイルを見つけやすい場所 (c:\scripts など) に保存します。

  5. 次の構文を使用して、スクリプトを実行します。

    & "<file path>\RunCmdletOnMultipleTenants.ps1" "<file path>\inputfile.csv"
    

    次に例を示します:

    & "c:\scripts\RunCmdletOnMultipleTenants.ps1" "c:\scripts\inputfile.csv"
    
  6. 各テナントにログオンし、スクリプトが実行されます。

RunCmdletOnMultipleTenants.ps1

注意

環境 (ConnectionUri 値) に合わせてスクリプト内の行を変更 Connect-IPPSSession する必要がある場合 があります。 詳細については、「Powershell のConnectをExchange Onlineする」を参照してください

# 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 EXO V2 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-IPPSSession -UserPrincipalName $UserName -ConnectionUri https://ps.protection.outlook.com/powershell-liveid/

# 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
}