Problems with Restore-SpSite due to incorrect database schema

Sometimes Restore-SPSite does not correctly report the problem. In my case I found out the database schemas do not match. You can goto Central Admin to confirm the server you backed up from and the server you’re restoring to.

I went ahead and made a powershell script to pull the data I needed.

one thing to note. it seems like there’s a bug on the output of SchemaVersionXml. the xml that’s returned does not close correctly. I’ve added a regular expression line to fix this problem. I’ll notify Microsoft of this.

Add-PSSnapin Microsoft.SharePoint.PowerShell;

$response = @{};
$response.success=$true;
$response.message="";

$contentdbs = Get-SPContentDatabase;

$hitList = @();
foreach($contentdb in $contentdbs) {
    $schema = $contentdb.SchemaVersionXml;
    $schema = $schema -ireplace '$', '';
    $schema = [xml]$schema;
    foreach($SchemaVersion in $schema.SchemaVersions.SchemaVersion) {
        $attributes = $SchemaVersion.Attributes;
        $target = @{};
        $target.ContentDatabase = $contentdb.Name;
        foreach ($attribute in $attributes) {
            $target[$attribute.Name] = $attribute.'#text';
        }
        $hitList += $target;
    }
}
$response.data = $hitList;

$response | ConvertTo-Json