PoshCode Archive  Artifact Content

Artifact 552ba611fbca8e09fa9921b531fddc8a9687aff91e73e84a5902e363e83eb491:

  • File WSS-MOSS-export.ps1 — part of check-in [6b766179f5] at 2018-06-10 12:56:57 on branch trunk — How to export Sharepoint with help of PowerShell (user: unknown size: 2654)

# encoding: ascii
# api: powershell
# title: WSS/MOSS export
# description: How to export Sharepoint with help of PowerShell
# version: 0.1
# license: CC0
# x-poshcode-id: 137
# x-archived: 2008-09-08T00:09:50
#
#
# Export sharepoint web contents with powershell like
# stsadm -o export -url http://localhost:80/wiki -filename export.cab -overwrite -versions 1
#
# http://www.sharepointblogs.com/mossms/default.aspx
# http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.deployment.aspx

param ( [string] $sitename = "http://localhost:80", [string] $relweburl = "/wiki")

# Load Assembly
[void] [System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") 


$spsite = new-object Microsoft.SharePoint.SPSite($SiteName)
$webpart = $spsite.openweb($relweburl, $false)


# Check type
if (!$webpart -is [Microsoft.SharePoint.SPWeb]) {
  Write-Host "Wrong type to export!" -foregroundcolor red
  exit
}


[System.Guid] $webguid = $webpart.ID
# $webguid.toString()


# Select Object to Export
[Microsoft.SharePoint.Deployment.SPExportObject] $exportObject = new-object Microsoft.SharePoint.Deployment.SPExportObject
$exportObject.Id = $webguid   
$exportObject.Type = [Microsoft.SharePoint.Deployment.SPDeploymentObjectType]::Web
$exportObject.ExcludeChildren = $FALSE
$exportObject.IncludeDescendants = [Microsoft.SharePoint.Deployment.SPIncludeDescendants]::All

# Export Settings
[Microsoft.SharePoint.Deployment.SPExportSettings] $expSettings = new-object Microsoft.SharePoint.Deployment.SPExportSettings
$expSettings.SiteUrl = $sitename
$expSettings.ExportObjects.Add($exportObject)
$expSettings.ExportMethod = [Microsoft.SharePoint.Deployment.SPExportMethodType]::ExportAll # Or ExportChanges
$expSettings.FileCompression = $TRUE
$expSettings.OverwriteExistingDataFile = $TRUE
$expSettings.BaseFileName = "export.cab"
$expSettings.IncludeSecurity = [Microsoft.SharePoint.Deployment.SPIncludeSecurity]::None # Or All
$expSettings.FileLocation = "."
$expSettings.LogFilePath = "./export.log"
$expSettings.IncludeVersions = [Microsoft.SharePoint.Deployment.SPIncludeVersions]::LastMajor
$expSettings.ExcludeDependencies = $FALSE
$expSettings.Validate()
# Show Settings
$expSettings

# Now Export
[Microsoft.SharePoint.Deployment.SPExport] $export = new-object Microsoft.SharePoint.Deployment.SPExport($expSettings)
$export.Run()

Write-Host "Done!"

trap [Exception] { 
      write-host $("`tTRAPPED: " + $_.Exception.GetType().FullName)
      write-host $("`tTRAPPED: " + $_.Exception.Message) 
      break
}