Office 365: How to get all the Groups and users per Group in an Office 365 tenant!

This time I am sharing a PowerShell script that allows you to list all groups defined in Office 365 (either distribution or security group or collaboration ones) and all members of each group. You can download the script from the following link:How to get all the Groups and users per Group in an Office 365 tenant!

   1: ############################################################################################################################################

   2: # Script that gets all the Groups on an Office 365 tenant and for each Group it also gets the users member of it.

   3: # Required Parameters:

   4: #  -> $sUserName: User Name to connect to the SharePoint Admin Center.

   5: #  -> $sMessage: Message to show in the user credentials prompt.

   6: #  -> $sInputFile: Message to show in the user credentials prompt.

   7: ############################################################################################################################################

   8: $host.Runspace.ThreadOptions = "ReuseThread"

   9:  

  10: #Definition of the function that allows to add to Office 365 the list of users contained in the CSV file.

  11: function Get-UsersAndGroupsOffice365

  12: {    

  13:     try

  14:     {   

  15:         Write-Host "Getting Office 365 Groups and Users ..." -foregroundcolor Green    

  16:         $gO365Groups=Get-MsolGroup

  17:         #$gCompartiMOSSGroup=Get-MsolGroup | Where {$_.DisplayName -eq "CompartiMOSS"}

  18:         #

  19:         foreach ($gO365Group in $gO365Groups) 

  20:         { 

  21:             Get-MsolGroupMember -GroupObjectId $gO365Group.ObjectId | Format-Table $gO365Group.DisplayName,DisplayName,EmailAddress

  22:         } 

  23:     }

  24:     catch [System.Exception]

  25:     {

  26:         write-host -f red $_.Exception.ToString()   

  27:     } 

  28: }

  29:  

  30: #Connection to Office 365

  31: $sUserName="<Office365_User>"

  32: $sMessage="Introduce your Office 365 Credentials"

  33: #Connection to Office 365

  34: $msolcred = get-credential -UserName $sUserName -Message $sMessage

  35: connect-msolservice -credential $msolcred

  36: Get-UsersAndGroupsOffice365

And this is the result you will get once you excute the script in PowerShell ISE:

image

2 pensamientos en “Office 365: How to get all the Groups and users per Group in an Office 365 tenant!

  1. Pingback: SharePoint 2013: Resumen de posts (LXI)! | Pasión por la tecnología...

  2. Pingback: SharePoint 2013: Resumen de posts (LXI)! - Blog de Juan Carlos González en Geeks.MS

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s