Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Please provide me powershell script to export the list from one web application to another web application. Only list structure need to copy like list name, columns etc not data

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

Here is the Powerhell code for exporting a list without contents.

$web = Get-SPWeb -Identity "SiteUrl"
$list = $web.Lists["ListName"]
$list.SaveAsTemplate("File_Name.stp", "List_Template_Title", 
"Description", $false);
share|improve this answer
    
I haven't tried your code, but is false something in PowerShell? I would expect $false –  eirikb Feb 20 at 8:58
    
Sorry it is a typo. You are right. It should be $false –  Nadeem Yousuf Feb 20 at 9:01
    
Updated the answer. –  Nadeem Yousuf Feb 20 at 9:02
1  
Great. Have my upvote :) (I usually don't care, but perhaps $web.Dispose()?) –  eirikb Feb 20 at 9:41
add comment

You can use the SPList.SaveAsTemplate cmdlet for that.

SPSite oSiteCollection = SPContext.Current.Site;
SPList oList = oSiteCollection.AllWebs["Site_Name"].Lists["List_Title"];
oList.SaveAsTemplate("File_Name.stp", "List_Template_Title", 
"Description", true);

Then upload the template file into your destination site's template gallery and you should be able to create a list from it.

Or, if you'd like to preserve all the content versions and permissions, you can use Export-SPWeb.

Export-SPWeb http://youSPSite/ -path ”D:\backup\Documents.cmp” -ItemUrl /Documents -IncludeVersions All -IncludeUserSecurity

**edit - I now see that my first code is c#. Crappy morning today, please have a look at Nadeem's code below to see the same method used in PowerShell

share|improve this answer
    
Http://yoursite( here i have to post site url or list url?) Itemurl( what i need to put here?) –  user21081 Feb 20 at 9:37
    
the url points to your site/web and the itemurl is a relative url to your list. Please have a look at the documentation that I provided. –  Rafał Saltarski Feb 20 at 10:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.