Saturday, 28 September 2019

Report Group and Teams Enabled SharePoint Online Sites using Powershell

In this post, I am going to share Powershell commands to find and list all SharePoint Online sites, the returned result object includes the property GroupEnabled (Groupify) which indicates the site is connected with group or not, and the result object also includes the property TeamEnabled (Teamify) which indicates whether the Teams feature enabled in the site's associated group or not.

Before proceeding, install SPO Powershell Module and run the below commands to connect Exchange Online (EXO) and SharePoint Online modules:
$Cred = Get-Credential
#Import Exchange Online Powershell module
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Cred -Authentication Basic -AllowRedirection
Import-PSSession $Session
#Connect SharePoint Service
Connect-SPOService -Url "https://YourTenantName-admin.sharepoint.com " -Credential $Cred

Export all SPO Sites with Group and Team Details

Here, we are fetching site details using the Get-SPOSite command and retrieve Office 365 Group object with Get-UnifiedGroup command, the group object includes the property resourceProvisioningOptions which includes the array of values, we need to check whether this array includes the value "Team" to identify the teams feature is configured or not in the group.
$Result = @()
$AllSites = Get-SPOSite -IncludePersonalSite:$False -Limit All | Select Title,URL
$TotalSites = $AllSites.Count
$i = 1 
ForEach ($Site in $AllSites) {
Write-Progress -Activity "Processing $($Site.Title)" -Status "$i out of $TotalSites completed"
$O365Group = $null;
$TeamEnabled = $false;
#Once again call Get-SPOSite for each site with -Detailed switch to get GroupId property
#The bulk enumeration command (Get-SPOSite -Limit All) do not support -Detailed switch
$GroupId = (Get-SPOSite $Site.URL -Detailed).GroupId.Guid
if($GroupId -ne $null) {
$O365Group = (Get-UnifiedGroup -Identity $GroupId -ErrorAction SilentlyContinue)
if($O365Group -ne $null -and $O365Group.resourceProvisioningOptions -contains "Team") {
$TeamEnabled = $true;
}
}
$Result += New-Object PSObject -property @{ 
SiteName = $Site.Title
SiteURL  = $Site.URL
GroupEnabled = if ($O365Group -ne $null) { $true } else { $false }
GroupName  = if ($O365Group -ne $null) { $O365Group.DisplayName } else { $null }
GroupID  = if ($O365Group -ne $null) { $GroupId } else { $null }
GroupMail  = if ($O365Group -ne $null) { $O365Group.PrimarySmtpAddress } else { $null } 
TeamEnabled  = $TeamEnabled   
}
$i++
}
$Result | Select SiteName,SiteURL,GroupEnabled,GroupName,GroupID,GroupMail,TeamEnabled |
Export-CSV "C:\\AllSPOSites.CSV" -NoTypeInformation -Encoding UTF8
The above commands store the details in the array object $Result, we can generate the required report from this result array.

List all sites without group feature

You can just filter the $Result array with Where-Object to list sites without a group.
$Result | Where-Object { $_.GroupEnabled -eq $false } | Select SiteName,SiteURL
Alternatively, you can list sites only that are connected with a group.
$Result | Where-Object { $_.GroupEnabled -eq $true } | Select SiteName,SiteURL,GroupName

Get all sites without group and teams feature

$Result | Where-Object { $_.GroupEnabled -eq $false -and $_.TeamEnabled -eq $false} | Select SiteName,SiteURL
Alternatively, you can list sites with group, but without teams feature.
$Result | Where-Object { $_.GroupEnabled -eq $true -and $_.TeamEnabled -eq $false} | Select SiteName,SiteURL,GroupName

Get all sites with group and teams feature

$Result | Where-Object { $_.GroupEnabled -eq $true -and $_.TeamEnabled -eq $true} | Select SiteName,SiteURL,GroupName

Sample CSV Report:

Find Group and Teams Enabled SharePoint Online Sites using Powershell

Advertisements
Advertisements

No comments:

Post a Comment