SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to move my site from a server to another.

I exported my site using Export-SPWeb, moved the data to destination server and ran the function below: (Taken from here.)

function import-spweb($sourceFile,$url,$retainObjectIdentity=$false,$includeSecurity=$true)
    $import = new-object Microsoft.SharePoint.Deployment.SPImport  
    $settings = new-object Microsoft.SharePoint.Deployment.SPImportSettings 
    $settings.FileLocation = [System.IO.Path]::GetDirectoryName($sourceFile)
    $settings.BaseFileName = [System.IO.Path]::GetFileName($sourceFile)
    $settings.SiteUrl = $url
    $settings.WebUrl = $url
    $settings.RetainObjectIdentity = $retainObjectIdentity

    if($includeSecurity){$settings.IncludeSecurity = [Microsoft.SharePoint.Deployment.SPIncludeSecurity]::All}
        else{$settings.IncludeSecurity = [Microsoft.SharePoint.Deployment.SPIncludeSecurity]::None}
    $settings.UpdateVersions = [Microsoft.SharePoint.Deployment.SPUpdateVersions]::Append
    $settings.UserInfoDateTime = [Microsoft.SharePoint.Deployment.SPImportUserInfoDateTimeOption]::ImportAll      

    $import.Add_ProgressUpdated({write-Progress "Importing" ("Objects: " + $_.ObjectsProcessed )  -perc -1})
    $import.Settings = $settings

Now, I did this before but somehow it doesn't work anymore and gives the error below:

Exception calling "Run" with "0" argument(s): "Object reference not set to an instance of an object."

I create destination site collection without a template by selecting "Select Later".

Any help would be great.

share|improve this question
up vote 1 down vote accepted

Have you considered doing this using a DB-Attach approach instead?

If you are using SP2007 you have some stsadm commands at your disposal, in SP2010 there are similar cmdlets in PowerShell.

Here is a blog post where I extract my sites from an existing database and merge them into another. TechNet samples on stsadm command.

On SP2010 there are also several approaches. Here is an article on moving content databases using PowerShell.

share|improve this answer
+1 for the great post. – frbry May 31 '11 at 15:33

Interestingly, using this tool solved my problem. I thought the program would be using the same methods. Any ideas?

share|improve this answer

Verify that the user running the script has permission on the database.

Verify that the same features are enabled at the source and destination site collection/site.

share|improve this answer
Yes the user I'm running the script with has full permission on the db and same features are enabled in both site. – frbry May 31 '11 at 17:28

Your Answer


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.