Skip to content

Instantly share code, notes, and snippets.

@tasgray
Last active November 20, 2016 13:42
Show Gist options
  • Save tasgray/421611ed458302b1939cbd564431c30b to your computer and use it in GitHub Desktop.
Save tasgray/421611ed458302b1939cbd564431c30b to your computer and use it in GitHub Desktop.
Loop through all Office 365 delegated admin tenants
#
# Managed Office 365 Delegated Admin Tenants.ps1
#
# Basic connection stuff
$cred = Get-Credential
Import-Module MsOnline
Connect-MsolService -Credential $cred
# Get list of tenants & loop
Get-MsolPartnerContract -All | ForEach {
# Get all users in an office 365 tenant
Write-Host ("Office 365 users for " + $_.Name)
# Replace this with any Office 365 cmdlet you want to run
# Make sure you keep the -TenantId parameter
Get-MsolUser -TenantId $_.TenantId.Guid
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment