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.

3 Answers 3


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.

  • +1 for the great post.
    – frbry
    May 31, 2011 at 15:33

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


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.

  • 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, 2011 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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