Hi @sns ,
According to my research and testing, please try to use the following PowerShell code to get the list of sub-sites from web application:
Get-SPWebApplication <WebApp URL> | Get-SPSite -Limit ALL | Get-SPWeb -Limit ALL
Hope it can help you. Thanks for your understanding.
---------------------------------------------------------------------
Update---------------------------------------------------------------------
Since you already have a CSV list of active site collections, please try to use the following script to get the list of sub-sites:
#Requirement: sharepoint online get all subsites powershell
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Variables
$SiteURL = Import-CSV -path "C:\siteurl.csv" -Header("url")
$Cred= Get-Credential
foreach ($Url in $SiteURL ){
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($Url.url)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Get the web
$Web = $Ctx.web
$Ctx.Load($Web)
#get all subsites in sharepoint online powershell
$Ctx.Load($Web.Webs)
$Ctx.executeQuery()
#Loop through each subsite and get subsite URL
ForEach ($Subweb in $web.Webs)
{
Write-host $Subweb.url
}
}
More information for reference: PowerShell to Get All Subsites in a Site Collection
Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.