SharePoint Migration – Export Content Database Details

This is article is next in the series of articles on “SharePoint Migration & Planning” Strategies. You can reach out to the previous articles in this series using the following links:

SharePoint Migration: Planning & Guidance On SharePoint Objects
SharePoint Migration – Export IIS Settings
SharePoint Migration – Export Alternate Access Mapping

In this article we will look for the PowerShell Scripts to export “SharePoint Content Databases” details from source SharePoint Farm. This information will be helpful to track all the “Content Databases” provisioned in SharePoint Farm.

In Step 1 we will add the PowerShell Snapin to PowerShell Script as usual

1

In Step 2 we define a function and initiate the export CSV file with Column Headers. For this demo I am exporting a few important properties like “Id, Content Database Name, Web Application Name, Server Name, Current Site Count” but you may query all possible properties as you deemed fit

In Step 3 we execute the “Get-SPContentDatabase” cmdlet to query the required properties

In Step 4 we loop through the properties collection for all Content Databases and list out the queried properties for each database

In Step 5 we add the content of properties for each of the Content Database to the CSV file

2

In Step 6 we will set the settings file path and call the function to export the Content Database Details

3

Once this script get executed successfully, it will export the Content Database Details in a CSV File as shown below in Step 7

4

We can see the exported details as shown below in Step 8

5

Code Reference:

Add-PSSnapin "Microsoft.SharePoint.PowerShell"Add-PSSnapin "Microsoft.SharePoint.PowerShell"
function Get-Content-Databases(){ Try {        if (Test-Path $settingsFilePath)        {            Remove-Item $settingsFilePath        }
        Add-Content $settingsFilePath "Id,Content Database Name,web Application Name,Server Name,Current Site Count"
        $contentDBSettings = Get-SPContentDatabase | Select Id,Name,webApplication,Server,CurrentSiteCount
        foreach ($contentDBSetting in $contentDBSettings)        {            $id = $contentDBSetting.Id            $name = $contentDBSetting.Name            $webApplication = $contentDBSetting.webApplication            $server = $contentDBSetting.Server            $currentSiteCount = $contentDBSetting.CurrentSiteCount
            $settings = "$id,$name,$webApplication,$server,$currentSiteCount"             Add-content $settingsFilePath $settings        }    }    Catch {         Write-Host $Error -ForegroundColor Yellow }}
Clear-Host
$settingsFilePath = "<CSV File Path>"
Get-Content-Databases

That is all for this demo.

Hope you find it helpful.

 

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s