This script allows you to get a list of all sites in a site collection in SharePoint Online / Office 365 using the Client Script Object Model.  This script requires references to the SharePoint Server 2013 Client Components SDK.  It can also be executed from a local SharePoint server.  Adjust the paths on the Add-Type statement as necessary.

Specify values in the following variables.

 

PowerShell
Edit|Remove
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"  
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"  
 
$siteUrl = “https://mytenant.sharepoint.com/sites/mysitecollection” 
$username = "admin@mytenant.onmicrosoft.com" 
$password = Read-Host -Prompt "Enter password" -AsSecureString  
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)  
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username$password)  
$ctx.Credentials = $credentials 
 
$rootWeb = $ctx.Web  
$sites  = $rootWeb.Webs 
 
$ctx.Load($rootWeb$ctx.Load($sites$ctx.ExecuteQuery() 
 
foreach($site in $sites) 
{ 
    $ctx.Load($site) 
    $ctx.ExecuteQuery() 
 
    Write-Host $site.Title "-" $site.Url  
}