Deep Dive Into Office 365 PowerShell Cmdlets (Part 8)

If you would like to read the other parts in this article series please go to:

In Part 7, we also explained Get-MsolGroup PowerShell cmdlet that you can use to retrieve the list of groups created in an Office 365 tenant and Get-MsolGroupMember PowerShell cmdlet to retrieve the member of the Office 365 groups. In this article, we will continue to explain a PowerShell script that you can use to provide a summary of Office 365 groups and another PowerShell script that will be useful to know as to how many Office 365 groups have been created without adding a description text. Both the PowerShell scripts, explained in this article, use Get-MsolGroup PowerShell cmdlet. To use both the PowerShell scripts, run it from a computer that have Windows Azure Active Directory Module for Windows PowerShell installed. It is assumed that you have connected to an Office 365 tenant using an account that has permissions to gather the data from Office 365 WAAD.

Reporting Office 365 Groups Summary

In case you need to report on the number of Office 365 groups created in an Office 365 tenant, you can use below PowerShell script. Below PowerShell script collects the number of Distribution List groups, the number of security groups, number of MainEnabledSecurity groups and the number of groups that have been synced from On-Premise Active Directory.
### Start Script ###

$Result = “C:\Temp\Result.CSV”
IF (Test-Path $Result)
{
Remove-item $Result
}
$STR = “Item, Value”
Add-Content $Result $STR

$Error.Clear()
$AllGroups = Get-Msolgroup -All
IF ($Error.Count -eq 0)
{
$TotDistGroups = ($AllGroups | Where-Object {$_.GroupType -eq ‘DistributionList’}).Count
$TotSecGroups = ($AllGroups | Where-Object {$_.GroupType -eq ‘Security’}).Count
$TotMailGroups = ($AllGroups | Where-Object {$_.GroupType -eq ‘MailEnabledSecurity’}).Count
$AllGroupsSynced = Get-Msolgroup -MaxResults 200 | Where-Object {$_.LastDirSyncTime –ne $null}

Write-Host “Total Distribution Groups: ” $TotDistGroups
Write-Host “Total Security Groups: ” $TotSecGroups
Write-Host “Total MailEnabledSecurity Groups: ” $TotMailGroups
Write-Host “Total Groups Synced from On-Premise Active Directory: ” $AllGroupsSynced

$STR = “Number of Distribution Groups:, “+$TotDistGroups
Add-Content $Result $STR
$STR = “Number of Security Groups:, “+$TotSecGroups
Add-Content $Result $STR
$STR = “Number of Mail Enabled Security Groups:, “+$TotMailGroups
Add-Content $Result $STR
$STR = “Number of Groups Synced from On-Premises:, “+$AllGroupsSynced
Add-Content $Result $STR
}
else
{
Write-Host “Some Errors occurred running Get-MsolGroup command”
}
Write-Host “Results saved in $Result”

### End Script ###

Once the script has finished executing, you will see a report file by name Result.CSV in C:\Temp folder. The report file looks like as shown in the screenshot below:

Image

Reporting Office 365 Groups without Description

When you create an Office 365 Group, you are asked to provide a description for the group. A Description field is provided for you to explain the purpose of creating the Office 365 group. While the Description field is optional, but it plays an important role when you have thousands of Office 365 groups created in an Office 365 Tenant and you don’t know why you created these groups. You can use below PowerShell script to get a list of Office 365 groups that do not have description set.
### Start Script ###

$Result = “C:\Temp\GroupsWithoutDescription.CSV”
IF (Test-Path $Result)
{
Remove-item $Result
}
$STR = “Item, Value, Group Type”
Add-Content $Result $STR

$Error.Clear()
$AllGroups = Get-Msolgroup –All | Where-Object {$_.Description –eq $null}
IF ($Error.Count -eq 0)
{
$TotDistGroups = ($AllGroups | Where-Object {$_.GroupType -eq ‘DistributionList’}).Count
$TotSecGroups = ($AllGroups | Where-Object {$_.GroupType -eq ‘Security’}).Count
$TotMailGroups = ($AllGroups | Where-Object {$_.GroupType -eq ‘MailEnabledSecurity’}).Count

Write-Host “Total Distribution Groups without Description: ” $TotDistGroups
Write-Host “Total Security Groups without Description: ” $TotSecGroups
Write-Host “Total MailEnabledSecurity Groups without Description: ” $TotMailGroups

$STR = “Number of Distribution Groups without Description:, “+$TotDistGroups
Add-Content $Result $STR
$STR = “Number of Security Groups without Description:, “+$TotSecGroups
Add-Content $Result $STR
$STR = “Number of Mail Enabled Security Groups without Description:, “+$TotMailGroups
Add-Content $Result $STR

ForEach ($allGroupsNow in $AllGroups)
{
$STRNew = “,”+$allGroupsNow.DisplayName+”,”+$allGroupsNow.GroupType
Add-Content $Result $STRNew
}

}
else
{
Write-Host “Some Errors occurred running Get-MsolGroup command”
}
Write-Host “Results saved in $Result”

### End Script ###

As you can see in the script above, we are using “$AllGroups = Get-Msolgroup | Where-Object {$_.Description –eq $null}” PowerShell command to get all Office 365 groups and then filter groups that do not have any text entered in the description field. Once the Script has finished executing, you will see the result in C:\Temp\GroupsWithoutDescription.CSV file. The report includes the number of security groups and the group name that does not have a description set as shown in the screenshot below:

Image

 Summary

In this part, we explained two PowerShell scripts that you can use to report a summary of Office 365 groups created in an Office 365 tenant and report on Office 365 groups that do not have a description text set. As you might have noticed in both the PowerShell scripts above, the scripts use Get-MsolGroup PowerShell cmdlet to collect the required information.
In the next part of this article series, we will provide more examples of using Office 365 Groups PowerShell cmdlet.  We will also provide a PowerShell script that you can use to report on the health status of Office 365 groups that sync from On-Premises Active Directory.

About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top