SharePoint PowerShell – Extract a list of all Site collections to a .csv file
Currently conducting a SharePoint Security audit project, I thought others might benefit from a series of PowerShell scripts that allow you to extract useful insights and details regarding your SharePoint online.
The first script is a simple PowerShell script that enables you to export a list of all your SharePoint site collections to a .csv file.
The extract contains the following details:
- Site URL
- Storage Usage
- Admins
- Is Connected to Teams: A boolean value which distinguishes Teams Sites VS SharePoint Sites
- Teams Channel Type (if applicable)
- Site Title
- Site Template
- M365 Group ID
- Number of subsites.
#Connect to Admin Center
Connect-SPOService -Url "https://yourtenant-admin.sharepoint.com"
#Get All site collections
$SiteCollections = Get-SPOSite -Limit All
$SiteReport = @()
#Iterate through each site
ForEach ($site in $siteCollections) {
# Generate a report of site collection properties
$siteReport += [PSCustomObject]@{
URL = $Site.Url
StorageUsage = $Site.StorageUsageCurrent
Admins= $Site.Owner
IsConnectedToTeams = $Site.IsTeamsConnected
TeamsChannelType=$Site.TeamsChannelType
Title=$Site.Title
Template=$Site.Template
GroupId=$Site.GroupId
SubSitesCount=($Site.WebsCount-1)
}
}
$SiteReport | Export-Csv -Path "C:\SPAudit\SiteCollections.csv" -NoTypeInformation
