SharePoint PowerShell: Backup and Restore a List or Document Library

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

About the Author

13 thoughts on “SharePoint PowerShell: Backup and Restore a List or Document Library

Leave a Reply

%d bloggers like this: