将独立 EOP 设置应用到多个租户的示例脚本

本文中的 PowerShell 脚本示例适用于管理多个独立Exchange Online Protection (EOP) 租户的管理员。 管理员可以使用本文中的脚本查看和/或将其配置设置应用于多个独立 EOP 租户。

在多个租户上运行脚本或 cmdlet

  1. 如果尚未安装,请安装 Exchange Online PowerShell 模块

  2. 使用电子表格应用 ((例如 Excel) )创建包含以下详细信息的.csv文件:

    • “用户名”列:用于连接 (的帐户, admin@contoso.onmicrosoft.com 例如,) 。
    • Cmdlet 列:例如,要运行 (的 cmdlet 或命令, Get-AcceptedDomainGet-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

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