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

Office 365: Como listar los Grupos y Miembros de cada Grupo de un tenant de Office 365!

En esta ocasión os dejo un script que permite listar todos los Grupos definidos en Office 365 (sean de distribución, de seguridad o de colaboración en grupo) y todos los miembros de cada Grupo. Podéis descargaros el script del siguiente enlace: 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

El resultado de la ejecución del script es el siguiente:

image