Skip to content

Instantly share code, notes, and snippets.

@kliemohn
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kliemohn/6881ddbafaacf8552f1b to your computer and use it in GitHub Desktop.
Save kliemohn/6881ddbafaacf8552f1b to your computer and use it in GitHub Desktop.
Copies sites from one SharePoint environment to another using DocAve 6 accessing the SharePoint environments remotely. Sets up the DocAve site groups, plans, and executes the plans as jobs.
Import-Module DocAveModule
function CreateCopyPlan($planName, $planDescription, $srcSitesGroupName, $destSitesGroupName, $srcSiteUrl, $destSiteUrl)
{
Write-Host "Creating copy plan $($planName)..."
$plan = Get-DAContentManagerBlankOnlinePlan
$plan.Name = $planName
$plan.Description = $planDescription
$plan.Action = "Merge"
$plan.SetPlanType("Copy")
# Setup source
$plan.SourceSPSitesGroupName = $srcSitesGroupName
$srcSiteCollection = New-Object DocAve.API.Objects.SharePointOnlineSite($plan.SourceSPSitesGroupName, $srcSiteUrl)
$plan.SourceTree.IncludeSPOnlineObject($srcSiteCollection)
# Setup destination
$plan.DestinationSPSitesGroupName = $destSitesGroupName
$destSiteCollection = New-Object DocAve.API.Objects.SharePointOnlineSite($plan.DestinationSPSitesGroupName, $destSiteUrl)
$plan.DestinationTree.SelectSPOnlineObject($destSiteCollection)
$plan.IncludeWorkflowDefinition = $true
$plan.ConflictResolution = [DocAve.API.Administration.ContentManager.ContentManagerConflictResolutionType]::ConflictResolutionOption10
$plan.AppsConflictResolution = [DocAve.API.Administration.ContentManager.ContentManagerAppsConflictResolutionType]::ReplaceAppAndAppData
$plan.NotificationName = "Kirk" # Ideally we create the notification via script as well
New-DAContentManagerOnlinePlan -Plan $plan
Write-Host "Done"
}
function CreateSPSitesGroup($name, $description, $siteUrls, $username, $securePassword)
{
$group = Get-DABlankSPOnlineSitesGroup
$group.Name = $name
$group.Description = $description
$group.AgentGroupName = "DEFAULT_SHAREPOINT_SITES_AGENT_GROUP"
$group.GroupType = "SharePointSitesGroup"
New-DASPOnlineSitesGroup -SitesGroup $group
$group = Get-DASPOnlineSitesGroup $name # not sure this is needed
foreach ($siteUrl in $siteUrls)
{
$site = $group.GetBlankSiteCollectionConfiguration()
$site.SetCredential($username, $securePassword)
$site.Url = $siteUrl
# Note: this will fail if the site collection is already in another group
$group.AddSiteCollection($site)
}
}
#
# Main
#
# Get Credentials
$srcSiteUsername = Read-Host -Prompt "Enter source site username"
$srcSitePasswordSecure = Read-Host -Prompt "Enter source site password" -AsSecureString
$destSiteUsername = Read-Host -Prompt "Enter destination site username"
$destSitePasswordSecure = Read-Host -Prompt "Enter destination site password" -AsSecureString
# In the future, the source and destination site collection URLs will be loaded from a file
$srcSiteUrls = @("https://srctenant.sharepoint.com/sites/dev_kliemohn", "https://srctenant.sharepoint.com/sites/dev_kliemohn2")
$destSiteUrls = @("https://desttenant.sharepoint.com/sites/dev_kliemohn1", "https://desttenant.sharepoint.com/sites/dev_kliemohn2")
Login-DAManager -ControlHost localhost -ControlPort 14000 -Username "admin" -PlainTextPassword "admin"
# Great the source and destination site groups
# This could be done just once and cover all site collections (does not need to be done once per batch, but could be)
$srcSitesGroupName = "SCRIPT Source Sites"
$destSitesGroupName = "SCRIPT Destination Sites"
CreateSPSitesGroup $srcSitesGroupName "Source sites for copy. Created using PowerShell." $srcSiteUrls $srcSiteUsername $srcSitePasswordSecure
CreateSPSitesGroup $destSitesGroupName "Destination sites for copy. Created using PowerShell." $destSiteUrls $destSiteUsername $destSitePasswordSecure
# Create the copy plans - there is one of these per site collection
# These can be put into plan groups (at least through the UI this is possible - hwe have not tried to do this via PowerShell)
$plan1 = "Script Test dev_kliemohn"
CreateCopyPlan $plan1 "Plan 1 Test" $srcSitesGroupName $destSitesGroupName $srcSiteUrls[0] $destSiteUrls[0]
$plan2 = "Script Test dev_kliemohn2"
CreateCopyPlan $plan2 "Plan 2 Test" $srcSitesGroupName $destSitesGroupName $srcSiteUrls[1] $destSiteUrls[1]
$plan1job = Run-DAContentManagerCopyJob -PlanName $plan1
$plan2job = Run-DAContentManagerCopyJob -PlanName $plan2
# At this point we can store the $plan1job.ID and $plan2job.ID and then use "Get-DAJob -ID <id>" and look at its progress and status
# We can also call Get-DAJobDetail, Get-DAJobSetting, GET-DAJobSummary, Download-DAJobReport, and Set-DAJobStopped
# We can also call Get-DAContentManagerJobConfigurationDetail and Get-DAContentManagerJobSecurityDetail
Logout-DAManager
Write-Host "DONE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment