Introduction
As I mentioned in a earlier post; I started working on Migration from SharePoint 2010 to SharePoint 2013 and power shell scripting.
Problem Background
Problem Background
After the migration we TEST-SPContentDatabase -Name "Name of the Content Database" -WebApplication "Name of the WebApplication" > C:\test.txt in order to test the migrated database.
In the text file we were able to find some migrated issues. One of that is MissingAssembly. So here I'm going to show how to solve it.
Solution
Please note that I used Phil Childs post in order to achieve this. http://get-spscripts.com/2011/08/diagnose-missingwebpart-and.html. I have automated by getting the missing assembly details to a text file and then getting the necessary details from the text file and removing the Event receiver, For more information please read Phil's post.
Here is the code.
You have to change the lines which are bold and italic, according to your data.
Add-PSSnapin Microsoft.SharePoint.PowerShell function Run-SQLQuery ($SqlServer, $SqlDatabase, $SqlQuery) { $SqlConnection = New-Object System.Data.SqlClient.SqlConnection $SqlConnection.ConnectionString = "Server =" + $SqlServer + "; Database =" + $SqlDatabase + "; Integrated Security = True" $SqlCmd = New-Object System.Data.SqlClient.SqlCommand $SqlCmd.CommandText = $SqlQuery $SqlCmd.Connection = $SqlConnection $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter $SqlAdapter.SelectCommand = $SqlCmd $DataSet = New-Object System.Data.DataSet $SqlAdapter.Fill($DataSet) $SqlConnection.Close() $DataSet.Tables[0] } Run-SQLQuery -SqlServer "Name of the SQL Server" -SqlDatabase "Name of the Content DB" -SqlQuery "SELECT * from EventReceivers where Assembly = 'Virtusa.Vplus.Leaderboards.EventReceivers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c3202aa47f1aa64d'" | select Id, Name, SiteId, WebId, HostId, HostType | Format-List | out-file -filepath "C:\Data.txt" $textData = Get-Content C:\Data.txt for($i=0; $i -le $textData.Length - 1; $i++) { $test = $textData.Get($i) if($test.StartsWith("Id")) { $test -match "Id : (?.*)" $Id = $matches['id'] Write-Host "Id: $Id" } if($test.Contains("SiteId")) { $test -match "SiteId : (? write-Host "Deleted Successfully" } catch { Write-Host "Cannot Delete" } } }.*)" $SiteId = $matches['SiteId'] Write-Host "SiteId: $SiteId" } if($test.Contains("WebId : ")) { $test -match "WebId : (? .*)" $WebId = $matches['WebId'] Write-Host "WebId: $WebId" } if($test.Contains("HostId : ")) { $test -match "HostId : (? .*)" $HostId = $matches['HostId'] Write-Host "HostId: $HostId" try { $site = Get-SPSite -Limit all | where {$_.Id -eq $SiteId} $web = $site | Get-SPWeb -Limit all | where {$_.Id -eq $WebId} write-Host "Web Url:" $web.Url write-Host "Site Url:" $site.Url $list = $web.Lists | where {$_.Id -eq $HostId} write-Host "List Name:" $list.Title $er = $list.EventReceivers | where {$_.Id -eq $Id} $er.Delete()
Conclusion
- Running this script will take a long time. So please schedule the time frame before start running the script.
No comments:
Post a Comment