Skip to content

Instantly share code, notes, and snippets.

@alexinnes
Last active September 29, 2015 11:04
Show Gist options
  • Save alexinnes/c8e8933f8b3bcee72fd6 to your computer and use it in GitHub Desktop.
Save alexinnes/c8e8933f8b3bcee72fd6 to your computer and use it in GitHub Desktop.
O365 Getting users from all groups
#Run this first - It will ask you to login (microsoft account)
Connect-MsolService
#This gets the domain
$domain = Get-MsolPartnerContract -DomainName #change me to the domain name e.g. someone.onmicrosoft.com
#this gets the users in the group
$groups = @(Get-MsolGroup -TenantId $domain.TenantId)
#This goes through the groups and lists the users.
foreach($element in $groups){$element.DisplayName; Get-MsolGroupMember -TenantId $domain.TenantId -GroupObjectId $element.ObjectID}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment