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.


1 Answer 1


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


Read more: https://www.sharepointdiary.com/2016/02/powershell-to-get-all-subsites-in-sitecollection-sharepoint-online.html#ixzz67o162L6J

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.