1

I've recently been appointed the companies admin for SharePoint. We use SharePoint Online. As personnel have come and gone they've been able to create their own team-sites. We apparently have no idea how many sites have been created, where they are and so forth.

Is there a PowerShell command that will allow us to see every single site and subsite that exists for our organization.

I also use SharePoint Designer if there is an easier method through that application.

1

You can use the SharePoint Online PowerShell, once you have install SPO management shell, you can use the below code:

Get all site collections and their subsites It will prompt for the password twice, then asked for the admin url and admin user name

Admin url: https:
Admin username:

here is the code

function Get-SPOAllWeb
{

   param (
   [Parameter(Mandatory=$true,Position=1)]
        [string]$Username,
        [Parameter(Mandatory=$true,Position=2)]
        $AdminPassword,
        [Parameter(Mandatory=$true,Position=3)]
        [string]$Url
        )
 $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
  $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword)
  $ctx.Load($ctx.Web.Webs)
  $ctx.Load($ctx.Web)
  $ctx.ExecuteQuery()

  Write-Host $ctx.Web.Url
  if($ctx.Web.Webs.Count -eq 0)
  {

  }
  else{
  foreach ($web in $ctx.Web.Webs)
  {
    Get-SPOAllWeb -Username $Username -AdminPassword $AdminPassword -Url $web.Url
  }}

}

$passie=Read-Host -Prompt "Password" -AsSecureString
$adminUrelek=Read-Host -Prompt "Admin url"
$adminUserName=Read-Host -Prompt "Admin username" 
Connect-SPOService -Url $adminUrelek -Credential $adminUserName
$sites=(Get-SPOSite).Url



foreach($url in $sites)
{

  Get-SPOAllWeb -Username $adminUserName -AdminPassword $passie -Url $url



}
  • As far as I understand this will not include the site collections created via Teams or Groups, right? – Kasper Bo Larsen Mar 29 '18 at 15:48
1

For all webs you can use the PNP library: https://docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-pnp/sharepoint-pnp-cmdlets?view=sharepoint-ps

Connect-PnPOnline –Url https://yoursite.sharepoint.com –Credentials (Get-Credential)
Get-PnPSubWebs -Recurse

For Site Collections...
You can use the SharePoint Online PowerShell cmdlet Get-SPOSite

https://docs.microsoft.com/en-us/powershell/module/sharepoint-online/get-sposite?view=sharepoint-ps

Download here: https://www.microsoft.com/en-us/download/details.aspx?id=35588

You will need to be a Tenant Admin.

Connect-SPOService https://YourDomain-admin.sharepoint.com
Get-SPOSite

To stay in the SPO cmdlets and not use PNP see: https://gallery.technet.microsoft.com/office/Script-to-get-All-Webs-in-c2c1cdaf

SharePoint Designer can only look at one site at a time.

  • So the return when I run the command is this: Run "Connect-SPOService" first. I run that and it asks for the URL, which I type in for both the corporate SharePoint landing page. xxx.SharePoint.com. It tells me the following: Current site is not a tenant administration site. So I try to run it for the specific site I need to see all sub-sites for and it tells me that it cannot authenticate to SharePoint Online using OAuth 2.0. – Shift7 Mar 27 '18 at 15:22
  • Yes, as in the sample above. – Mike Smith - MCT - MVP Mar 27 '18 at 15:24

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.