Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
If you use the Built-in security add-on for on-premises mailboxes, you can use the script in this article to view (and with modification, configure) the configuration settings in the different organizations you manage.
To run a script or cmdlet in multiple organizations with the Built-in security add-on for on-premises mailboxes
If you haven't already, install the Exchange Online PowerShell module.
Using Microsoft Excel or another spreadsheet app, create a .csv file with the following details:
- UserName column: The account you use to connect to the cloud (for example,
admin@contoso.onmicrosoft.com). - Cmdlet column: The cmdlet or command to run (for example,
Get-AcceptedDomainorGet-AcceptedDomain | Format-Table Name).
The .csv file looks like this:
UserName,Cmdlet admin@contoso.onmicrosoft.com,Get-AcceptedDomain | Format-Table Name admin@fabrikam.onmicrosoft.com,Get-AcceptedDomain | Format-Table Name- UserName column: The account you use to connect to the cloud (for example,
Save the .csv file in a location that's easy to find (for example, c:\scripts\inputfile.csv).
Copy the RunCmdletOnMultipleTenants.ps1 script into Notepad or another text editor, and then save the file to a location that's easy to find (for example, c:\scripts).
Run the script by using the following syntax:
& "<file path>\RunCmdletOnMultipleTenants.ps1" "<file path>\inputfile.csv"Here's an example:
& "c:\scripts\RunCmdletOnMultipleTenants.ps1" "c:\scripts\inputfile.csv"The script signs in to and runs in each cloud organization.
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 Exchange Online 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
}