Created
November 20, 2016 13:47
-
-
Save tasgray/e292c4ef42baadebe7085972213925bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Manage Exchange Online Delegated Tenants.ps1 | |
# | |
# Setup credentials | |
$cred = Get-Credential | |
Connect-MsolService -Credential $cred | |
# Get list of tenants & loop | |
Get-MsolPartnerContract -All | ForEach { | |
$tenantprefix = [string]$_.DefaultDomainName | |
# Configure the connection url - note the DelegatedOrg parameter | |
$ConnectionUri = "https://ps.outlook.com/powershell-liveid?DelegatedOrg=$tenantprefix" | |
# Connect to Exchange & import session | |
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $ConnectionUri -Credential $cred -Authentication Basic -AllowRedirection | |
Import-PSSession $Session -AllowClobber | |
## | |
## Run some exchange cmdlets here | |
## | |
# Remove the session - avoid hitting 3 session limit | |
Remove-PSSession $Session | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment