Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dev-kperera/c9ea15d8999cb87dcdff5847756b6710 to your computer and use it in GitHub Desktop.
Save dev-kperera/c9ea15d8999cb87dcdff5847756b6710 to your computer and use it in GitHub Desktop.
Eventhough we could migrate OneDrive content with PowerShell. I'm giving a try to migrate content with ShareGate PowerShell addins.
# tenants
$tenantOne = connect-site -Url https://tenantOne-admin.sharepoint.com -Browser
$tenantTwo = connect-site -Url https://tenantTwo-admin.sharepoint.com -Browser
# List of unique user names of users need to migrate
$csvFile = "C:\OneDriveMirationUserEmailList.csv"
$table = Import-Csv $csvFile -Delimiter ";"
# ShareGate incrementatl copy config. This will be only usable if you are copying incrementally
$copysettings = New-CopySettings -OnContentItemExists IncrementalUpdate
<#
Other options:
New-CopySettings [[-OnWarning] <OnWarningAction {Continue | Cancel}>] [[-OnError] <OnErrorAction {Skip | SkipAllVersions | Cancel}>] [[-OnSiteObjectExists] <OnSiteObjectExistsAction {Merge | Skip}>] [[-OnContentItemExists] <OnContentItemExistsAction {Overwrite | Skip | Rename | IncrementalUpdate}>] [[-VersionOrModerationComment] <String>]
#>
# user names
$tenantTwoAdmin = "admintwo@tenantOne.onmicrosoft.com"
$tenantOneAdmin = "adminone@tenantTwo.onmicrosoft.com"
# Passwords
$tenantOneAdminPswd = ConvertTo-SecureString "1eafawtrf" -AsPlainText -Force
$tenantTwoAdminPswd = ConvertTo-SecureString "rhgtrehfd" -AsPlainText -Force
foreach ($row in $table)
{
# definitions
$upn = $row.login
$OneUPN = $upn + "@tenantOne.onmicrosoft.com"
$TwoUPN = $upn + "@tenantTwo.onmicrosoft.com"
# write to console
$dateTime = Get-Date
Write-Output "________________________________________________________________________________"
Write-Output $dateTime
Write-Output "________________________________________________________________________________"
# getting Two user config
$TwoPersonalSite = Get-OneDriveUrl -Tenant $tenantTwo -Email $TwoUPN
Write-Output "Copying from : $TwoPersonalSite"
# getting One user config
$OnePersonalSite = Get-OneDriveUrl -Tenant $tenantOne -Email $OneUPN
Write-Output "Copying to : $OnePersonalSite"
# copy content config
$site = Connect-Site -Url $TwoPersonalSite -Username $tenantTwoAdmin -Password $tenantTwoAdminPswd
$dstlist = Get-List -Site $site.Site -Name "Documents"
$site = Connect-Site -Url $OnePersonalSite -Username $tenantOneAdmin -Password $tenantOneAdminPswd
$srclist = Get-List -Site $site.Site -Name "Documents"
#region COPY
# full copy - uncomment below if you are performing a full copy
# Copy-Content -SourceList $srclist -DestinationList $dstlist
# Incremental copy
Copy-Content -SourceList $srcList -DestinationList $dstList -CopySettings $copysettings
#endregion COPY
}
<#
Got questions? Post your question on Twitter and dont forget to tag me with @meetKushan
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment