Beispielskript für das Anwenden von EOP-Einstellungen für mehrere Mandanten

Das PowerShell-Beispielskript in diesem Artikel richtet sich an Administratoren, die mehrere eigenständige Exchange Online Protection-Mandanten (EOP) verwalten. Administratoren können das Skript in diesem Artikel verwenden, um ihre Konfigurationseinstellungen auf mehrere eigenständige EOP-Mandanten anzuzeigen und/oder anzuwenden.

So führen Sie ein Skript oder Cmdlet auf mehreren Mandanten aus:

  1. Falls noch nicht geschehen, installieren Sie das Exchange Online PowerShell-Modul.

  2. Erstellen Sie mithilfe einer Tabellenkalkulations-App (z. B. Excel) eine .csv-Datei mit den folgenden Details:

    • UserName-Spalte: Das Konto, das Sie zum Herstellen einer Verbindung verwenden (z. B admin@contoso.onmicrosoft.com. ).
    • Cmdlet-Spalte: Das auszuführende Cmdlet oder der Auszuführende Befehl (z. B Get-AcceptedDomain . oder Get-AcceptedDomain | Format-Table Name).

    Die .csv-Datei sieht wie folgt aus:

    UserName,Cmdlet
    admin@contoso.onmicrosoft.com,Get-AcceptedDomain | Format-Table Name
    admin@fabrikam.onmicrosoft.com,Get-AcceptedDomain | Format-Table Name
    
  3. Speichern Sie die .csv Datei an einem leicht zu findenden Speicherort (z. B. c:\scripts\inputfile.csv).

  4. Kopieren Sie das RunCmdletOnMultipleTenants.ps1 Skript in Editor, und speichern Sie die Datei dann an einem leicht zu findenden Speicherort (z. B. c:\scripts).

  5. Führen Sie das Skript mit der folgenden Syntax aus:

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

    Hier ist ein Beispiel:

    & "c:\scripts\RunCmdletOnMultipleTenants.ps1" "c:\scripts\inputfile.csv"
    
  6. Jeder Mandant wird bei angemeldet, und das Skript wird ausgeführt.

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
}