Script di esempio per l'applicazione delle impostazioni di Exchange Online Protection autonomo a più tenant

Lo script di PowerShell di esempio in questo articolo è destinato agli amministratori che gestiscono più tenant autonomi Exchange Online Protection (EOP). Gli amministratori possono usare lo script in questo articolo per visualizzare e/o applicare le impostazioni di configurazione a più tenant EOP autonomi.

Eseguire uno script o un cmdlet su più tenant

  1. Se non è già stato fatto, installare il modulo Exchange Online PowerShell.

  2. Usando un'app foglio di calcolo (ad esempio, Excel), creare un file di .csv con i dettagli seguenti:

    • Colonna UserName: l'account che verrà usato per connettersi, admin@contoso.onmicrosoft.comad esempio .
    • Colonna cmdlet: il cmdlet o il comando da eseguire , Get-AcceptedDomain ad esempio o Get-AcceptedDomain | Format-Table Name.

    Il file .csv sarà simile al seguente:

    UserName,Cmdlet
    admin@contoso.onmicrosoft.com,Get-AcceptedDomain | Format-Table Name
    admin@fabrikam.onmicrosoft.com,Get-AcceptedDomain | Format-Table Name
    
  3. Salvare il file .csv in un percorso facile da trovare, ad esempio c:\scripts\inputfile.csv.

  4. Copiare lo scriptRunCmdletOnMultipleTenants.ps1 nel Blocco note e quindi salvare il file in un percorso facile da trovare, ad esempio c:\scripts.

  5. Eseguire lo script utilizzando la seguente sintassi:

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

    Ecco un esempio:

    & "c:\scripts\RunCmdletOnMultipleTenants.ps1" "c:\scripts\inputfile.csv"
    
  6. Ogni tenant verrà connesso a e lo script verrà eseguito.

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
}