Monday 24 May 2021

Migrating Multiple Teams between 2 tenants from a list of URL's using ShareGate PowerShell.

If you are lucky enough to have a license to ShareGate, you may find yourself using the Copy Team functionality. The Desktop App is pretty good if you want to move multiple teams with a nice search function and it even lets you know if there are Team name conflicts before you start migrating.

However if one or both of your tenants have thousands of Teams, the list of Teams in the ShareGate Desktop app can take a very long time to fully load. In this case you may want to speed up the process by using a PowerShell script that reads from a text file containing a list of Teams URL's. Teams URL's aren't the most friendly, but they usually contain the Group ID, which can be used by the ShareGate PowerShell "Copy-Team" command. Note: there can be a conflict between the ShareGate module and the official Microsoft Teams PowerShell module, so I would recommend you avoid installing the Teams PowerShell module on your ShareGate server.

Here's the full script I created to copy a list of Teams:

$mySourceTenant = Connect-Tenant -Domain https://<<sourcetenantname>>-admin.sharepoint.com -Browser -DisableSSO

$myDestTenant = Connect-Tenant -Domain https://<<destinationtenantname>>-admin.sharepoint.com -Browser -DisableSSO

$sites = Get-Content -path "C:\scriptlocation\Sites.txt"

$idArr = New-Object System.Collections.ArrayList

#loop to create an array of group ID's

foreach ($s in $sites) {

    #This is only required if your list contains the full Team URL, if you already have the group ID you can remove the next 2 lines

    $endUrl = $s.Substring($s.IndexOf("groupId")+8)

    $gId = $endUrl.Substring(0, $endUrl.IndexOf("&"))

    $idArr.Add($gId)

}


$teams = Get-Team -Id $idArr -Tenant $mySourceTenant -AllowMultiple

Copy-Team -Team $teams -DestinationTenant $myDestTenant

Migrating Multiple Teams between 2 tenants from a list of URL's using ShareGate PowerShell.

If you are lucky enough to have a license to ShareGate, you may find yourself using the Copy Team functionality. The Desktop App is pretty g...