Office 365 groups is a wonderful tool for Ad Hoc Collaboration and is the backbone of Yammer groups and now Team as well. The problem is that since end users can create them, they tend to explode in number and size, and they count against your total quota for your tenant. They also don’t show up in the SharePoint Admin interface so they can be hard to manage. However, you can go grab them in Powershell.
First off, let’s see what we get from the Get-SPOSite command
$UserName="[email protected]"
$Password ='pass@word1'
#Setup Credentials to connect
$Credentials = New-Object System.Management.Automation.PSCredential($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))
#Connect-MsolService -Credential $Credentials
Connect-SPOService -Url "https://tenant-admin.sharepoint.com" -Credential $Credentials
$spoSite = Get-SPOSite https://tenant.sharepoint.com/sites/groupname
$spoSite | Format-List
This gives us a site and we can look at the properties for it.
LastContentModifiedDate : 4/26/2017 5:30:35 PM
Status : Active
ResourceUsageCurrent : 0
ResourceUsageAverage : 0
StorageUsageCurrent : 34
LockIssue :
WebsCount : 1
CompatibilityLevel : 15
DisableSharingForNonOwnersStatus :
Url : https://tenant.sharepoint.com/sites/O365GroupName
LocaleId : 1033
LockState : Unlock
Owner : 7edf8826-ac0c-48e6-93d4-a76a3ad91432_o
StorageQuota : 26214400
StorageQuotaWarningLevel : 25574400
ResourceQuota : 300
ResourceQuotaWarningLevel : 200
Template : GROUP#0
Title : Office 365 Group Title
AllowSelfServiceUpgrade : True
DenyAddAndCustomizePages : Enabled
PWAEnabled : Unknown
SharingCapability : ExistingExternalUserSharingOnly
SandboxedCodeActivationCapability : Check
DisableCompanyWideSharingLinks : NotDisabled
DisableAppViews : NotDisabled
DisableFlows : NotDisabled
StorageQuotaType :
ShowPeoplePickerSuggestionsForGuestUsers : False
SharingDomainRestrictionMode : None
SharingAllowedDomainList :
SharingBlockedDomainList :
Note the Template of GROUP#0, this will enable us to pull all of the groups by using the -Template switch on the Get-SPOSite cmdlet.
Once we do that we can simply grab the LastContentModifiedDate and the StorageUsageCurrent to see when it was last used and how much is stored in the site collection. We can also use the WebsCount to see if they have created subsites as well.
So, the final code would look like this:
$UserName="[email protected]"
$Password ='pass@word1'
#Hash Table to hold results
$groups = @{}
#Setup Credentials to connect
$Credentials = New-Object System.Management.Automation.PSCredential($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))
#Connect-MsolService -Credential $Credentials
Connect-SPOService -Url "https://tenant-admin.sharepoint.com" -Credential $Credentials
foreach($spoSite in (Get-SPOSite -Limit All -Template 'GROUP#0' -IncludePersonalSite:$false))
{
$groups.Add($spoSite.Url,@{})
$groups[$spoSite.Url].Add("Title",$spoSite.Title)
$groups[$spoSite.Url].Add("Size",$spoSite.StorageUsageCurrent)
$groups[$spoSite.Url].Add("Last Modified",$spoSite.LastContentModifiedDate)
$groups[$spoSite.Url].Add("Subsites",$spoSite.WebsCount)
}
$exp = @("Url, Group Name, Size, Last Modified, Subsites")
Foreach($g in $groups.keys)
{
$exp += ("$($g)", "$($groups[$g]["Title"])", "$($groups[$g]["Size"])", "$($groups[$g]["Last Modified"])", "$($groups[$g]["Subsites"])" -join ",")
}
$exp | Out-File "C:GroupsUsage.csv" -Encoding ascii
One thing that I have done here is to store everything in a HashTable to make exporting this to a CSV easier. Then I can save that as an XLSX and format it as a table and then sort and filter it as needed. Here is an example of what it looks like: