SharePoint PowerShell: Backup and Restore a List or Document Library 8

Sometimes some of the most simplest things are the easy to forget. I had a situation where I was asked, ‘Hey how can I export a list for safekeeping and restore it later from a script?’ My natural answer is sure that’s easy, but after a few minutes I realized…’duh’. I figured I’d put it out there just in case.

So for our example we have the following list.

List image

The list in this case of interest is the ‘test’ list.

 Export-SPWeb "http://www.domain.com/" -itemurl "/Lists/test" -path "c:\test.cmp"

Please note the trailing slash on the URL.

Now if we deleted the list through some horrible mistake the import command is as follows.

Import-SPWeb "http://www.domain.com/" -Path "c:\test.cmp"

There are various flags that can be added like ‘-force’ or ‘-UpdateVersions’. If you need more information take a look at the associated TechNet Articles I’ve included below. Note this assumes you have administrative level access to PowerShell on the farm. You can also use the central admin to do granular backup jobs but PowerShell gives you a level of control and flexibility that you can’t find in the GUI. You are still required to use PowerShell to restore.

-Javi

Sources:
Import-SPWeb

Export-SPWeb

  • jnsnfl

    How do you use the -nofilecompression switch??

  • Robert

    I think you saved my weekend ;)

  • Javier Barrera

    pretty easily, just add the -NoFileCompression switch as part of the command. This help when you export is large. It also give you change to peak into the XML file that organizes the export. Make sure you have an empty folder and plenty of space.

  • Santosh Bantu

    Export-SPWeb “http://www.domain.com/” -itemurl “/Lists/test” -path “c:test.cmp”
    Use “/” symbol before Lists/test else it would give Argument Exception

  • Santosh Bantu

    Export-SPWeb “http://www.domain.com/” -itemurl “/Lists/test” -path “c:test.cmp”
    Use “/” symbol before Lists/test else it would give Argument Exception

  • Javier Barrera

    Thanks for the correction. SharePoint is a stickler for details

  • rider
  • Rajendhiran Muthusamy

    Thank you very much for your valuable post.

Switch to our mobile site