PowerShell - SharePointOnline - Queries the active site collections in O365 tenant to generate reports based on template type used by the site collection
# Requires Windows PowerShell version
3
$tenant=""
<#
Description:
Queries the active site collections in O365 tenant to generate reports
based on template type used
by the site collection. And will generate report with all site
collections in tenant.
Details of the discovered sites are written to a .csv file for each
template type.
The .csv files will be found in the directory the script is ran from.
Requirements:
SharePoint Online Management Shell - Current build
http://www.microsoft.com/en-us/download/details.aspx?id=35588
==============================================================
#>
# Set tenant values
$SPOAdminCenter = "https://$tenant-admin.sharepoint.com"
$AdminCredential = ""
#Report Files Names
$reportNameGroups = "GroupsSiteInfo_$((Get-Date).ToString("yyyy-MM-dd_hh.mm.ss")).csv"
$reportNameOD4B = "OneDriveForBusinessSiteInfo_$((Get-Date).ToString("yyyy-MM-dd_hh.mm.ss")).csv"
$reportNameClassic = "ClassicSiteInfo_$((Get-Date).ToString("yyyy-MM-dd_hh.mm.ss")).csv"
$reportNamePWA = "PWASiteInfo_$((Get-Date).ToString("yyyy-MM-dd_hh.mm.ss")).csv"
$reportNameBlog = "BlogSiteInfo_$((Get-Date).ToString("yyyy-MM-dd_hh.mm.ss")).csv"
$reportNameComm = "CommunicationsSiteInfo_$((Get-Date).ToString("yyyy-MM-dd_hh.mm.ss")).csv"
$reportNameNoOD4B = "AllSiteInfoNoOD4B_$((Get-Date).ToString("yyyy-MM-dd_hh.mm.ss")).csv"
$reportName = "AllSiteInfo_$((Get-Date).ToString("yyyy-MM-dd_hh.mm.ss")).csv"
#Connect to tenant. You will be
prompted to enter your password.
Import-Module -WarningAction SilentlyContinue Microsoft.Online.SharePoint.PowerShell
try {
Write-Host "Connecting
to tenant..."
Connect-SPOService -Url
$SPOAdminCenter -Credential
$AdminCredential
}
catch {
Write-Host "Failed
to connect to tenant."
}
#Get all site collections using Office
365 Groups Modern Team Site template
Write-Host "Obtaining list of
sites using Groups Modern Team Site template..." -ForegroundColor Green
Write-Host "Writing site list
and properties to export file." -ForegroundColor
Blue
Get-SPOSite -Template GROUP#0 -Limit All | Export-Csv -Path $reportNameGroups -NoTypeInformation
-Append
Write-Host "Groups Modern Sites
information has been written to $reportNameGroups." -ForegroundColor
Green
Write-Host ""
#Get all site collections using One
Drive for Business Modern Site template
#Possible templates used are SPSPERS,
SPSPERS#8, SPSPERS#10 but using SPSPERS should get all.
Write-Host "Obtaining list of
OneDrive for Business site collections..." -ForegroundColor
Green
Write-Host "Writing site list
and properties to export file." -ForegroundColor
Blue
Get-SPOSite -Template SPSPERS -Limit All -IncludePersonalSite:$true | Export-Csv -Path $reportNameOD4B -NoTypeInformation
-Append
Write-Host "One Drive for
Business sites information has been written to $reportNameOD4B." -ForegroundColor
Green
Write-Host ""
#Get all site collections using
Classic Team Site template
#Possible templates used are STS#0
& EHS#1 but using STS#0 should get all.
Write-Host "Obtaining list of
sites using Classic Team Site collections..." -ForegroundColor Green
Write-Host "Writing site list
and properties to export file." -ForegroundColor
Blue
Get-SPOSite -Template STS#0 -Limit All | Export-Csv -Path $reportNameClassic -NoTypeInformation
-Append
Write-Host "Classic Team sites
information has been written to $reportNameClassic." -ForegroundColor
Green
Write-Host ""
#Get all site collections using
Project Web Application template
Write-Host "Obtaining list of
sites using Project Web Application template..." -ForegroundColor Green
Write-Host "Writing site list
and properties to export file." -ForegroundColor
Blue
Get-SPOSite -Template PWA#0 -Limit All | Export-Csv -Path $reportNamePWA -NoTypeInformation
-Append
Write-Host "Project Web
Application sites information has been written to $reportNamePWA."
-ForegroundColor Green
Write-Host ""
#Get all site collections using
Classic Blog Site template
Write-Host "Obtaining list of
sites using Classic Blog Site template..." -ForegroundColor
Green
Write-Host "Writing site list
and properties to export file." -ForegroundColor
Blue
Get-SPOSite -Template BLOG#0 -Limit All | Export-Csv -Path $reportNameBlog -NoTypeInformation
-Append
Write-Host "Classic Blog Sites
information has been written to $reportNameBlog." -ForegroundColor
Green
Write-Host ""
#Get all site collections using
Communication Site template
Write-Host "Obtaining list of
sites using Communication Sites template..." -ForegroundColor Green
Write-Host "Writing site list
and properties to export file." -ForegroundColor
Blue
Get-SPOSite -Template SitePagePublishing#0 -Limit
All |
Export-Csv -Path
$reportNameComm -NoTypeInformation
-Append
Write-Host "Communication Sites
information has been written to $reportNamePWA." -ForegroundColor
Green
Write-Host ""
#Get all site collections excluding
OneDrive For Business using any site template
Write-Host "Obtaining list of
all site collections excluding OneDrive for Business sites..." -ForegroundColor Green
Write-Host "Writing site list
and properties to export file." -ForegroundColor
Blue
Get-SPOSite -Limit All | Export-Csv -Path $reportNameNoOD4B -NoTypeInformation
-Append
Write-Host "All site collection
information has been written to $reportNameNoOD4B." -ForegroundColor
Green
Write-Host ""
#Get all site collections including
OneDrive For Business using any site template
Write-Host "Obtaining list of
all site collections..." -ForegroundColor
Green
Write-Host "Writing site list
and properties to export file." -ForegroundColor
Blue
Get-SPOSite -Limit All -IncludePersonalSite:$true | Export-Csv -Path $reportName -NoTypeInformation
-Append
Write-Host "All site collection
information has been written to $reportName." -ForegroundColor
Green
Write-Host ""
Comentarios