Getting all SharePoint sites from root directory
-
08-02-2021 - |
Question
So I am new SharePoint online administrator and working at a small company. I got a task to move my company into SharePoint which before were used minimaly without much of administration.
Today I found out that there is at least a few sites that is in root directory. As most sites are https://companyname.sharepoint.com/sites/SiteName
, these are in https://companyname.sharepoint.com/SiteName. I currently trying to get a list of these sites to prepare a plan on how to deal with them, I tried using Get-SPOSite
in sharepoint, but showed only sites that I can see in admin panel as well.
Solution
You can get this using the PNPPowerShel
#Get Credentials to connect
$Cred = Get-Credential
Connect-PnPOnline -Url https://teanat-admin.sharepoint.com -Credentials $Cred
$allsites = Get-PnPTenantSite
foreach($site in $allsites)
{
Try {
#Connect to PNP Online
Connect-PnPOnline -Url $Site.url -Credentials $Cred
#Get subsites in SharePoint Online using PnP PowerShell
$WebsCollection = Get-PnPSubWebs -Recurse
ForEach($Web in $WebsCollection)
{
Write-host "Site Collection URL =" $site.Url " has this subwebs =" $Web.Url
}
}
catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
}
Disconnect-PnPOnline
Read more: https://www.sharepointdiary.com/2016/02/powershell-to-get-all-subsites-in-sitecollection-sharepoint-online.html#ixzz67o162L6J
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange