How to check if subsite exist in sharepoint online through SharePoint Online management shell. I can not see any Get-SPOWeb command like Get-SPOSite

2 Answers 2


I had the same need, so I turned to using CSOM in PowerShell and created this function for our PowerShell module. It does not recurse through the entire site, it just returns the subsites off of the root site collection, but might help you get started anyway.

Function Get-AllSPOWebs{
        Returns an array of subsites below the provided URL. Does not recurse.
        Returns an array of subsites below the provided URL, this is not a recursive function.
        .PARAMETER Url
        The URL of the site to find subsites for.
        The following would get all the subsites from the Auburn site, then do something with them.
        $subsites = Get-AllSPOWebs -Url "https://tenant.sharepoint.com/sites/site"
        foreach ($site in $subsites){
            #Do something
        $returnWebs = @()
        $context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
        $context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($credential.UserName, $credential.Password)
        $rootWeb = $context.Web
        $childWebs = $rootWeb.Webs
        $returnWebs += $rootWeb
        foreach($childWeb in $childWebs){
            $returnWebs += $childWeb
        return $returnWebs

To get Sites as well as Site groups, please refer to the script below:

Connect-SPOService –url https://site-admin.sharepoint.com

$sites = Get-SPOSite -Detailed

foreach ($site in $sites)

    Write-Host $site.Title
    $siteGroups = Get-SPOSiteGroup -Site $site.Url

    foreach ($group in $siteGroups)
              $users = Get-SPOUser -Site $site.Url  -Group $group.Title -Limit All |ft -wrap 
              $url = $site.Url
              $groupName = $group.Title
              Write-Host $groupName + ' ' + $group.Users


You can follow this link.. Above code is referenced from here.

  • Hardik, I know Get-SPOSite. I want to check if sub site exist or not in sharepoint online. Commented Feb 15, 2016 at 12:17
  • Hello Bhaskar, I have edited my answer. Please check if it works for you.. :)
    – Hardik
    Commented Feb 15, 2016 at 12:53
  • Thanks Hardik , But I guess you copied wrong script snippet . I will refer link shared and will get back if anything else is required. Commented Feb 15, 2016 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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