Script de ejemplo para aplicar configuración de EOP independiente a varios espacios empresariales

El script de PowerShell de ejemplo de este artículo es para administradores que administran varios inquilinos de Exchange Online Protection independientes (EOP). Los administradores pueden usar el script de este artículo para ver o aplicar sus opciones de configuración a varios inquilinos de EOP independientes.

Para ejecutar un script o un cmdlet en varios inquilinos:

  1. Si aún no lo ha hecho, instale el módulo de PowerShell Exchange Online.

  2. Con una aplicación de hoja de cálculo (por ejemplo, Excel), cree un archivo .csv con los detalles siguientes:

    • Columna UserName: la cuenta que usará para conectarse (por ejemplo, admin@contoso.onmicrosoft.com).
    • Columna cmdlet: cmdlet o comando que se va a ejecutar (por ejemplo, Get-AcceptedDomain o Get-AcceptedDomain | Format-Table Name).

    El archivo .csv tendrá este aspecto:

    UserName,Cmdlet
    admin@contoso.onmicrosoft.com,Get-AcceptedDomain | Format-Table Name
    admin@fabrikam.onmicrosoft.com,Get-AcceptedDomain | Format-Table Name
    
  3. Guarde el archivo .csv en una ubicación fácil de encontrar (por ejemplo, c:\scripts\inputfile.csv).

  4. Copie el script RunCmdletOnMultipleTenants.ps1 en el Bloc de notas y, a continuación, guarde el archivo en una ubicación fácil de encontrar (por ejemplo, c:\scripts).

  5. Ejecute el script con la sintaxis siguiente:

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

    Aquí le mostramos un ejemplo:

    & "c:\scripts\RunCmdletOnMultipleTenants.ps1" "c:\scripts\inputfile.csv"
    
  6. Cada inquilino iniciará sesión en y se ejecutará el script.

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
}