Wednesday 18 February 2015

PowerShell to do restructuring of SharePoint content

You might have went through scenario where most SharePoint implementations have outgrown the original purpose for which they were designed at initials – what might was envisioned as a simple solution has now become a complex environment. This has resulted your complex environment - one that is constantly undergoing changes in content and usability. However, in spite of these changes, SharePoint continues to cater to the growing and varied needs of the organization. As a result, there is a continuous need for periodic restructuring of content and metadata.

In market you would find many 3rd party tool to done this job, but each of them will require license and this is what lenthy process to bring in operation. You have a great handy tool available to do this job, powerShell.

You can use the Export-SPWeb and Import-SPWeb cmdlets to move heavy subsites to new destination or can even restructure URL:

Import-SPWeb:
http://technet.microsoft.com/en-us/library/ff607613(v=office.14).aspx
Export-SPWeb:
http://technet.microsoft.com/en-us/library/ff607895(v=office.14).aspx

The general syntax of these commands are:

Export-SPWeb [-Identity] <url of the site to be exported> -Path <location and name of the file to be created after export> [-Force] [-IncludeUserSecurity] [-IncludeVersions <LastMajor | CurrentVersion | LastMajorAndMinor | All>] [-ItemUrl <Any specific item to export, like document library or list>]
Import-SPWeb [-Identity] <url of the site to be exported> -Path <location and name of the file to be imported from> [-Confirm] [-Force] [-IncludeUserSecurity] [-UpdateVersions <Append | Overwrite | Ignore>]
You can use the IncludeUserSecurity parameter to export the associated security with the site, library, or list which includes users in the site, authors of documents and lists, when the document or list was created and modified, etc... and the IncludeVersions parameter to specify which versions of the documents or list items you want to export, whether to export current versions, last major versions, last major or minor versions or all versions, etc.

  • If your SQL Server version supports database snapshot (Enterprise and Developer editions) , it is recommended to use UseSqlSnapshot parameter with Export-SPWeb command for a more consistent backup. 
  • Workflows are not included when we export/import contents of sites, libraries, or lists.
Valid migration scenarios when using the Publishing features are the following:
  • Export the site collection starting at the root site and then import it as the root site into a new site collection
  • Export subsites of the site collection and then import them as subsites into an existing site collection that has the Publishing features enabled
Some manual work may be required to ensure master pages and page layouts that are in use in the subsites are copied over to the new site collection.

If your environments have customizations, such as custom template you might receive error as below while import

[2/12/2014 3:14:51 PM]: Progress: Initializing Import.
[2/12/2014 3:15:08 PM]: FatalError: Could not find WebTemplate #10011 with LCID 1033. at Microsoft.SharePoint.Deployment.ImportRequirementsManager.VerifyWebTemplate(SPRequirementObject reqObj) at Microsoft.SharePoint.Deployment.ImportRequirementsManager.Validate(SPRequirementObject reqObj) at Microsoft.SharePoint.Deployment.ImportRequirementsManager.DeserializeAndValidate() at Microsoft.SharePoint.Deployment.SPImport.VerifyRequirements() at Microsoft.SharePoint.Deployment.SPImport.Run() [2/12/2014 3:15:14 PM]: Progress: Import Completed. [2/12/2014 3:15:14 PM]: Finish Time: 2/2/2014 3:15:14 PM. [2/12/2014 3:15:14 PM]: Completed with 0 warnings. [2/12/2014 3:15:14 PM]: Completed with 1 errors.

Use below script to check available webtemplates in the farm or in target farm if you moving to another farm.
get-spwebtemplate | select name,title,id

If any of the missing template(10011) does not exist in target farm, you will need to install those features in farm .

No comments:

Post a Comment