2

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

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{
    <#
        .SYNOPSIS
        Returns an array of subsites below the provided URL. Does not recurse.
        .DESCRIPTION    
        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.
        .EXAMPLE
        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
        }
    #>
    param(
        [Parameter(Mandatory=$true)][string]$Url
    )
    begin{
        $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
        $context.Load($rootWeb)
        $context.Load($childWebs)
        $context.ExecuteQuery()
    }
    process{
        $returnWebs += $rootWeb
        foreach($childWeb in $childWebs){
            $context.Load($childWeb)
            $context.ExecuteQuery()
            $returnWebs += $childWeb
        }
    }
    end{
        return $returnWebs
        $context.Dispose()
    }
}
1

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
          }
} 

OR

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. – Bhaskar Dhone Feb 15 '16 at 12:17
  • Hello Bhaskar, I have edited my answer. Please check if it works for you.. :) – Hardik Feb 15 '16 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. – Bhaskar Dhone Feb 15 '16 at 13:05

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.