Tag Archives: Migration

Undeclare / Declare all / some records in a list

Requirement

Undeclare all records in a SharePoint list. Declare all records in a SharePoint list. Declare only specific records in a SharePoint list.

Solution

Use the following PowerShell script.

$SPAssignment = Start-SPAssignment
$web = Get-SPWeb <a href="http://your-site">http://your-site</a> -AssignmentCollection $spAssignment
$list = $web.lists["your-list"].items
foreach ($item in $list)
{
	$IsRecord = [Microsoft.Office.RecordsManagement.RecordsRepository.Records]::IsRecord($Item)
	if ($IsRecord -eq $true){
		Write-Host "Undeclared $($item.Title)"
		[Microsoft.Office.RecordsManagement.RecordsRepository.Records]::UndeclareItemAsRecord($Item)
	}
}
Stop-SPAssignment $SPAssignment

To declare all items as a record, change the relevant code above to the following:

	if ($IsRecord -ne $true){
		Write-Host "Declared $($item.Title)"
		[Microsoft.Office.RecordsManagement.RecordsRepository.Records]::DeclareItemAsRecord

To declare specific items as a record, based on a condition

	$IsRecord = [Microsoft.Office.RecordsManagement.RecordsRepository.Records]::IsRecord($Item)
	if ($IsRecord -ne $true){
		if ($item["Status"] -eq "Completed")
		{ 
			Write-Host "Declared $($item.Title)"
			[Microsoft.Office.RecordsManagement.RecordsRepository.Records]::DeclareItemAsRecord($Item)
		}
	}

This will declare as record only items that have ‘Status’ equal to Completed.

Comments ( 4 )

Migrated data contains old workflow columns/fields

Problem

When migrating items from a list with associated workflows, the migrated items retain the metadata fields associated with the list. This includes all workflow columns which you most likely would not need.

Solution

Deassociate the workflows from the original list prior to moving the list items.

  1. Go to List Settings -> Workflow Settings -> Remove Workflow and remove all the workflows.
  2. Move / copy the items.

 

Comments ( 0 )

Migrate sites using database attach method

Requirement

Recently had to reinstall SharePoint for our developer. He had a content database with a bunch of site collections in it and he wanted to keep it after the farm was reinstalled.

Solution

After reinstalling SharePoint:

  1. Re-attach the database in SQL Management Studio.
  2. Mount the content database in powershell and attach it to the web application by running the following command:
Mount-SPContentDatabase -Name <DatabaseName> -DatabaseServer <ServerName>
-WebApplication <URL> [-Updateuserexperience]

You should now see all the site collections that are in the database. This will also create the managed paths for each site collection. Note that if any of the managed paths are in use, the site collection will not be ‘imported’. In my case, I had to delete the site collection that was using ‘/’ and re-attach the content database.

 

Comments ( 0 )