2

Is there someone who created a working script for SPOnline that lists in Excel compatible the URL of all subsites in a site collection?

Something like this

www.domain.com
www.domain.com\subsiteA
www.domain.com\subsiteB
www.domain.com\subsiteB\Subsite01
1

This should do the trick - just call the last two lines for each site collection, I usually do it with a CSV list of site collection URLs from another command (can't remember the SPO one to get all site collection URLs, but it's the equivalent of Get-SpSite in server side OM) piped into a for..each loop.

Note you need to run this in a shell where you've imported the Microsoft.SharePoint.Client and Microsoft.SharePoint.Client.Runtime DLLs - if you don't have these, download them as part of the 'SharePoint Online Client Components SDK' and add lines to the top using Add-Type with the path to the DLLs.

function Get-SPOWebs(){ 
param( 
   $Url = $(throw "Please provide a Site Collection Url"), 
   $Credential = $(throw "Please provide a Credentials") 
) 

  $context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)   
  $context.Credentials = $Credential  
  $web = $context.Web 
  $context.Load($web) 
  $context.Load($web.Webs) 
  $context.ExecuteQuery() 
  foreach($web in $web.Webs) 
  { 
       Get-SPOWebs -Url $web.Url -Credential $Credential  
       $web >> path\to\output\file
  } 
} 

$UserName = "yourusername@tenant" 
$Password = "yourpassword" 
$SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force 
$SPOCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword) 

$AllWebs = Get-SPOWebs -Url 'https://tenant/site/collection' -Credential $SPOCredentials 
$AllWebs | %{ Write-Host $_.Title }
  • About your second paragraph: I was thinking of using the SharePoint online management shell. Is that ok or I still have to add those DLL? – susan Aug 23 '17 at 12:42
  • It should work with just the SPO shell but if not, then add the DLLs. – Thomas Gass Aug 23 '17 at 12:42
  • I got errors, should I use windows powershell ISe to be able to write all of that? – susan Aug 24 '17 at 11:48
  • the portion for authentication needs to be amended for accounts who have the multifactor authentication – susan Aug 24 '17 at 14:25
  • Or seeing as you only need to run it as one account, just use one without MFA enabled. I don't deal with any tenants that use MFA, personally I think it's just a pain. Would appreciate it if you mark this as the answer as it does what was asked. – Thomas Gass Aug 25 '17 at 10:21

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.