################################################################################################## # # Author : Encodian Solutions Ltd # Date : 2019-07-08 # Last : 2019-07-08 # Notes : Script to: # Find all site collections and subsites of a tenant and write the Name & Url to a csv file # # Usage : Fill out the parameters then run the script # # History : # ################################################################################################## ################################ # Parameters to specify # # The SP Online tenant name, for example: # $orgName="encodian" $orgName="" # Specify .csv location, for example: # $filePath = "C:\Encodian\DataDocs\" # $fileName = "deploy.csv" $filePath = "" $fileName = "deploy1.csv" $env:dp0 = [System.IO.Path]::GetDirectoryName($filePath) $csvPath = "$env:dp0\$fileName" # # End of parameters ################################ ################## # Main Function ################## # Get all subsites and call itself recursively function Get-SPOAllWeb { param ( [Parameter(Mandatory=$true,Position=1)] [string]$Url, [Parameter(Mandatory=$true,Position=2)] [string]$CSVPath ) $conn = Connect-PnPOnline -Url $Url -UseWebLogin -ReturnConnection $subwebs = Get-PnPSubWebs -Recurse foreach ($web in $subwebs){ $line = $web.Title + "," + $web.Url + "," + ",,"; Add-Content $CSVPath $line Write-Host $web.Url } } ##################### # Main Function Call ##################### Connect-PnPOnline -Url https://$orgName-admin.sharepoint.com -UseWebLogin # Add header row to .csv Add-Content $csvPath "Name,Url,Status,Message" # Get all site collections from tenant and process $sites=Get-PnPTenantSite foreach($site in $sites) { $line = $site.Title + "," + $site.Url + "," + ",,"; Add-Content $CSVPath $line Write-Host $site.Title $site.Url Get-SPOAllWeb -Url $site.Url -CSVPath $csvPath }