For Host named site collection, SPSite is null. When we are reading the database using Unattached database method.

Gaurav Kumar3 (CS) 20 Reputation points
2023-12-02T11:39:24.84+00:00
When we are trying to read the host names site collection using ConnectAsUnattachedDatabase through database via power shell. We are getting NULL for SPSite .

Here is the script : -  

$dbName = "My_WSS_Content" 
$dbServer = "My-W2K22-SS19" 

$ContentDb = Get-SPContentDatabase -DatabaseName $dbName -DatabaseServer $dbServer -ConnectAsUnattachedDatabase 

Write-Host $ContentDb.Sites.Count; 

foreach($name in $ContentDb.Sites.Names) 
{ 
     Write-Host $name 
} 

Write-Host '=============' 
foreach($site in $ContentDb.Sites) 
{ 
    if($site -eq $null) 
    { 
              Write-Host 'null detetced'  
    } 
    else 
    { 
        if ($site.HostHeaderIsSiteName) 
        { 
            Write-Host $site.Url 'is host-named'  
        } 
        else 
        {  
          Write-Host $site.Url 'is path based'  
        } 
    } 
} 

Output : -  

5 

/ 

/sites/Mobiles 

thinkpadhost.demo.com:26148 

thinkpadhost.demo.com:26148/departments/marketing 

thinkpadhost.demo.com:26148/IT/Server

 ============= 

http://gk3-w2k22-sp19:12204 is path based 

http://gk3-w2k22-sp19:12204/sites/Mobiles is path based 

null detetced 

null detetced 

null detetced 


Microsoft 365 and Office SharePoint Development
Microsoft 365 and Office SharePoint For business Windows
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2023-12-04T06:16:41.74+00:00

    Hi @Gaurav Kumar3 (CS),

    Per your description, the issue should relate to the backend of the sharepoint 2019. Since we are unable to fix the issue, I would recommend you to raise a new ticket in feedback. Many features of our current products are designed and upgraded based on customers’ feedback. With requirements like this increase, the problem may well be released in the future. Thanks for your understanding.


    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.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.