Recently we discovered an issue where the Site Deleting event receiver was being triggered when we migrated teamsites from one content DB to another. This was something we never anticipated since we were just moving sites and not deleting them. We figured out that the event receiver was being triggered since the custom teamsite data was being deleted from the source content DB.
So we decided to come up with a powershell script to restore the list and DB table.In my opinion Powershell scripting just rocks. I just want to share some snippets from the code that updates a SharePoint list and DB.
$web = $site.RootWeb
$web.AllowUnsafeUpdates = $TRUE
$teamsitemasterlist = $web.GetList($TeamsiteListName)
$newlistitem = $teamsitemasterlist.Items.Add()
$newlistitem["Title"] = $teamsiteTitle
$newlistitem["Description"] = $teamsiteDescription
$newlistitem["Provisioning Status"] = "Provisioned"
$newlistitem.Update()
$sqlconnection = new-object System.Data.SqlClient.SQLConnection
$sqlconnection.ConnectionString = $connectionstring
$sqlconnection.Open()
$sqlcommand = new-object System.Data.SqlClient.SQLCommand
$sqlcommand.Connection = $sqlconnection
$query = "Insert Query to update DB"
$sqlcommand.CommandText = $query
$rows = $sqlcommand.ExecuteNonQuery()
Hope this helps.
We then came up with couple of more scripts to mitigate the issue in the future when we need to migrate additional teamsites
1) Script to delete the Site deleting Event Handler for the sites prior to the migration of sites. The script reads the list of files from the xml output of stsadm -o enumsites -url http://xxxx/
2)Script to re-register the Site Deleting Event Handler for the sites post migration.
So we decided to come up with a powershell script to restore the list and DB table.In my opinion Powershell scripting just rocks. I just want to share some snippets from the code that updates a SharePoint list and DB.
$web = $site.RootWeb
$web.AllowUnsafeUpdates = $TRUE
$teamsitemasterlist = $web.GetList($TeamsiteListName)
$newlistitem = $teamsitemasterlist.Items.Add()
$newlistitem["Title"] = $teamsiteTitle
$newlistitem["Description"] = $teamsiteDescription
$newlistitem["Provisioning Status"] = "Provisioned"
$newlistitem.Update()
$sqlconnection = new-object System.Data.SqlClient.SQLConnection
$sqlconnection.ConnectionString = $connectionstring
$sqlconnection.Open()
$sqlcommand = new-object System.Data.SqlClient.SQLCommand
$sqlcommand.Connection = $sqlconnection
$query = "Insert Query to update DB"
$sqlcommand.CommandText = $query
$rows = $sqlcommand.ExecuteNonQuery()
Hope this helps.
We then came up with couple of more scripts to mitigate the issue in the future when we need to migrate additional teamsites
1) Script to delete the Site deleting Event Handler for the sites prior to the migration of sites. The script reads the list of files from the xml output of stsadm -o enumsites -url http://xxxx/
2)Script to re-register the Site Deleting Event Handler for the sites post migration.
Comments
Post a Comment