Partilhar via


Get a list of all your Site Collections on your Web Application

Here is a quick script for SharePoint 2007 to get all your site collections and their assoicated databases. In SharePoint 2010 - the code is much simplier due to the Powershell Cmdlets but here is the long way. It saves your results to a file on your C:\. Just replace "WebApp" with your web application name. Good luck!

[Reflection.Assembly]::LoadFile("C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\Microsoft.SharePoint.dll")

$webappname = "webapp"

$uri = New-Object System.Uri("https://$webappname")

$spWebApp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($uri)

$sites = $spWebApp.Sites

foreach ($site in $sites)

{

    if ($site.ReadLocked -eq $False){

  $dbprop = [Microsoft.SharePoint.Administration.SPContentDatabase].GetProperty("Name")

      $dbName = $dbprop.GetValue($site.ContentDatabase, $null)

      $url = $site.ServerRelativeUrl.toString()

      Add-Content  "C:\$webappname.csv" "$url,$dbName"

    }

}

Comments

  • Anonymous
    October 18, 2011
    The comment has been removed