Share via


여러 테넌트에 독립 실행형 EOP 설정을 적용하기 위한 샘플 스크립트

이 문서의 샘플 PowerShell 스크립트는 여러 EOP(독립 실행형 Exchange Online Protection) 테넌트 관리 관리자를 위한 것입니다. 관리자는 이 문서의 스크립트를 사용하여 여러 독립 실행형 EOP 테넌트에서 구성 설정을 보고/또는 적용할 수 있습니다.

여러 테넌트에 대해 스크립트 또는 cmdlet을 실행하려면

  1. 아직 설치하지 않은 경우 Exchange Online PowerShell 모듈을 설치합니다.

  2. 스프레드시트 앱(예: Excel)을 사용하여 다음 세부 정보가 포함된 .csv 파일을 만듭니다.

    • UserName 열: 연결하는 데 사용할 계정입니다(예: admin@contoso.onmicrosoft.com).
    • Cmdlet 열: 실행할 cmdlet 또는 명령(예: 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

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