Last active
August 29, 2015 14:16
-
-
Save SriharshaShesham/cfeb9d967f63084df649 to your computer and use it in GitHub Desktop.
Copying Lists Between Sites/SitesCollection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Check if SharePoint is already snapped in | |
if ( (Get-PSSnapin -Name "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue) -eq $null ) | |
{ | |
Add-PsSnapin "Microsoft.SharePoint.Powershell" | |
} | |
# $sourceWebsiteUrl is the URL of the site from which you want to copy the list | |
$sourceWebsiteUrl = "http://YourSoureceURL/SiteName" | |
# $destinationWebsiteUrl is the URL of the site to which you wan to copy the list | |
$destinationWebsiteUrl="http://YourDestURL/SiteName" | |
# $path is a temporary directory which is used to store the imported content. Any directory is fine | |
$path = "C:\Users\UserName\Documents\Powershell\Sharepoint Administration\CopyingListsBetweenSites" | |
# $lists is an array of list names of the source website which you want to copy to the destination website. | |
$lists= @("Is Insured","Claims", "Claim Processing Stages", "Claim Status", "Insurance Companies", "Reference Claim Status", "Qualification", "Speciality") | |
foreach($list in $lists) | |
{ | |
try | |
{ | |
Write-Host "Exporting " + $sourceWebsiteUrl + "/lists/" +$list | |
export-spweb -Force $sourceWebsiteUrl -ItemUrl ("lists/" + $list) -IncludeUserSecurity -IncludeVersions All -path ($path + $list + ".cmp") | |
Write-Host "Exporting complete" | |
} | |
catch | |
{ | |
Write-Host "Exporting failed" | |
} | |
try | |
{ | |
Write-Host "Importing " + $destinationWebsiteUrl + "/lists/" + $list | |
import-spweb $destinationWebsiteUrl -IncludeUserSecurity -path ($path + $list + ".cmp") | |
Write-Host "Importing complete" | |
} | |
catch | |
{ | |
Write-Host "Importing failed" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment