GoDaddy Office365 to Microsoft Office365 Migration- Part 8

Clone Teams and Teams channels

The next step is to get the teams and teams channels created. Its again cloning the configurations without data in SharePoint Online. Data will be migrated as part of SharePoint data migration using Mover.

Since we have exported the teams data earlier, The same dump can be used with some minor adjustments like user UPN. Here is a sample script which will help to get the teams and team channels cloned as per the export files made from source tenant.

In my experience, Teams is bit tricky and sometimes needs some time to get settled after creation. For example, If the script is trying to create a team “Finance” and a private channel “PayRoll” with in Finance Team, Sometimes the channel creation fails if tried to create the channel immediately after creating the Finance Team. Keeping this in mind, the script is have a sleep of 10 seconds, which may not be sufficient. If so, rerun the script again after few minutes so that failed sections will get successfully completed.

Another important point on Teams PowerShell module. The current version of Teams PowerShell Module is 3.2.1. In case if some commandlet is not working as expected with 3.2.1, Try with 3.2.2 which is in public preview now.

If (Test-Path "C:\GoDaddyTenant\Export\Teams\TeamsDetails.CSV" -IsValid)
    {
    Connect-MicrosoftTeams
    Connect-AzureAD
    $TeamsDetails = Import-Csv -Path "C:\GoDaddyTenant\Export\Teams\TeamsDetails.CSV"
    $TeamChannelsDetails = Import-Csv -Path "C:\GoDaddyTenant\Export\Teams\TeamChannelDetails.csv"
    Foreach($TDetails in $TeamsDetails)
        {
        Write-Host "Creating Teams " $TDetails.DisplayName
        [bool]$TDetails.Archived = $TDetails.Archived
        [bool]$TDetails.AllowStickersAndMemes = $TDetails.AllowStickersAndMemes
        [bool]$TDetails.AllowCustomMemes = $TDetails.AllowCustomMemes
        [bool]$TDetails.AllowGiphy = $TDetails.AllowGiphy
        [bool]$TDetails.AllowGuestCreateUpdateChannels = $TDetails.AllowGuestCreateUpdateChannels
        [bool]$TDetails.AllowGuestDeleteChannels = $TDetails.AllowGuestDeleteChannels
        [bool]$TDetails.AllowCreateUpdateChannels = $TDetails.AllowCreateUpdateChannels
        [bool]$TDetails.AllowCreatePrivateChannels = $TDetails.AllowCreatePrivateChannels
        [bool]$TDetails.AllowDeleteChannels = $TDetails.AllowDeleteChannels
        [bool]$TDetails.AllowAddRemoveApps = $TDetails.AllowAddRemoveApps
        [bool]$TDetails.AllowCreateUpdateRemoveTabs = $TDetails.AllowCreateUpdateRemoveTabs
        [bool]$TDetails.AllowCreateUpdateRemoveConnectors = $TDetails.AllowCreateUpdateRemoveConnectors
        [bool]$TDetails.AllowUserEditMessages = $TDetails.AllowUserEditMessages
        [bool]$TDetails.AllowUserDeleteMessages = $TDetails.AllowUserDeleteMessages
        [bool]$TDetails.AllowOwnerDeleteMessages = $TDetails.AllowOwnerDeleteMessages
        [bool]$TDetails.AllowTeamMentions = $TDetails.AllowTeamMentions
        [bool]$TDetails.AllowChannelMentions = $TDetails.AllowChannelMentions
        [bool]$TDetails.ShowInTeamsSearchAndSuggestions = $TDetails.ShowInTeamsSearchAndSuggestions
        [bool]$TDetails.ShowInTeamsSearchAndSuggestions = $TDetails.ShowInTeamsSearchAndSuggestions
        New-Team -DisplayName $TDetails.DisplayName -Description $TDetails.Description -MailNickName $TDetails.MailNickName -Visibility $TDetails.Visibility -GiphyContentRating $TDetails.GiphyContentRating -AllowGiphy $TDetails.AllowGiphy -AllowStickersAndMemes $TDetails.AllowStickersAndMemes -AllowCustomMemes $TDetails.AllowCustomMemes -AllowGuestCreateUpdateChannels $TDetails.AllowGuestCreateUpdateChannels -AllowGuestDeleteChannels $TDetails.AllowGuestDeleteChannels -AllowCreateUpdateChannels $TDetails.AllowCreateUpdateChannels -AllowDeleteChannels $TDetails.AllowDeleteChannels -AllowAddRemoveApps $TDetails.AllowAddRemoveApps -AllowCreateUpdateRemoveTabs $TDetails.AllowCreateUpdateRemoveTabs -AllowCreateUpdateRemoveConnectors $TDetails.AllowCreateUpdateRemoveConnectors -AllowUserEditMessages $TDetails.AllowUserEditMessages -AllowUserDeleteMessages  $TDetails.AllowUserDeleteMessages -AllowOwnerDeleteMessages $TDetails.AllowOwnerDeleteMessages -AllowTeamMentions $TDetails.AllowTeamMentions -AllowChannelMentions $TDetails.AllowChannelMentions -ShowInTeamsSearchAndSuggestions $TDetails.ShowInTeamsSearchAndSuggestions
        Start-Sleep -Seconds 10
        }
    Write-Host "Proceeding with Team Channel Creation...." -ForegroundColor Yellow
    $TeamsChannelCount = $TeamChannelsDetails.length
    For ($j = 0; $j -lt  $TeamsChannelCount; $j++)
        {
        If ($TeamChannelsDetails.DisplayName[$j]  -ne "General")
            {
            Write-Host Creating Teams Channel $TeamChannelsDetails.DisplayName[$j] inside $TeamChannelsDetails.TeamName[$j]
            $TargetGroupID = Get-Team -DisplayName $TeamChannelsDetails.TeamName[$j] |Where-Object {$_.DisplayName -eq $TeamChannelsDetails.TeamName[$j]}
            If ($TargetGroupID -ne $null)
                {
                New-TeamChannel -GroupId $TargetGroupID.GroupID -DisplayName $TeamChannelsDetails.DisplayName[$j] -Description $TeamChannelsDetails.Description[$j] -MembershipType $TeamChannelsDetails.MembershipType[$j]
                }
            Else
                {
                Write-Host Group ID Missing. Please check if the parent Team was created successfully. If the Team was created successfully, Please re-run the script after some time
                }
            } 																
        }
    Disconnect-MicrosoftTeams
    }
Else
    {
    Write-Host Input File Missing. Please run Teams Export Script to generate an input file with all required data from Source Tenant.
    }

Once Teams and Teams Channel creation is successful, Give few hours and start with updating the permissions. At this point, Setting ownership of private channel using Add-TeamChannelUser commandlet is having some bug. However, membership is getting added as expected with MicrosoftTeams module 3.2.2 which is in public preview now. This commandlet was in the preview from last few version however not mature yet :).

Here is a sample script which can help to clone the Team/Team Channel (Private Channels) permissions.

#Update SourceDomainName & DestinationOnMicrosoftDomainName first.
$SourceDomainName = "YourDomain.com"
$DestinationOnMicrosoftDomain = "yourdomain.onmicrosoft.com"


If (Test-Path "C:\GoDaddyTenant\Export\Teams\TeamsDetails.CSV" -IsValid)
    {
    Connect-MicrosoftTeams -verbose
    Connect-AzureAD -Verbose
    $TeamsDetails = Import-Csv -Path "C:\GoDaddyTenant\Export\Teams\TeamsDetails.CSV"
    $TeamChannelsDetails = Import-Csv -Path "C:\GoDaddyTenant\Export\Teams\TeamChannelDetails.csv"
    Foreach($TDetails in $TeamsDetails)
        {
        [string] $TeamUserPermissionFile = "C:\GoDaddyTenant\Export\Teams\Permissions\TeamPermission_"+$TDetails.GroupId+".csv"
        $TargetGroupID = Get-Team -DisplayName $TDetails.DisplayName |Where-Object {$_.DisplayName -eq $TDetails.DisplayName}
        $Permissions = Import-Csv $TeamUserPermissionFile 
        Foreach($UserPermission in $Permissions) 
            {
            Write-Host Entering Permission assignment on $TDetails.DisplayName for $UserPermission.User
            $uName = $UserPermission.User
            If ($uName -match $SourceDomainName)
                {
                $TargetUser = $Uname -replace  $SourceDomainName, $DestinationOnMicrosoftDomain
                Write-Host $uName adjusted to $TargetUser -ForegroundColor Green
                Get-AzureADUser -SearchString $TargetUser
                IF(Get-AzureADUser -SearchString $TargetUser -ErrorAction SilentlyContinue)
                    {
                    Write-Host Adding $TargetUser as $UserPermission.Role
                    Add-TeamUser -GroupId $TargetGroupID.GroupID -User $TargetUser -Role $UserPermission.Role
                    }
                Else
                    {
                    Write-Host "Account missing in Azure AD - " $TargetUser
                    }
                }
            } 
        }
    Write-Host "Proceeding with Team Channel permission assignment...." -ForegroundColor Yellow
    $TeamsChannelCount = $TeamChannelsDetails.length
    For ($j = 0; $j -lt  $TeamsChannelCount; $j++)
        {
        If ($TeamChannelsDetails.DisplayName[$j]  -ne "General")
            {
            Write-Host Creating Teams Cahnnel $TeamChannelsDetails.DisplayName[$j] inside $TeamChannelsDetails.TeamName[$j]
            $TargetGroupID = Get-Team -DisplayName $TeamChannelsDetails.TeamName[$j] |Where-Object {$_.DisplayName -eq $TeamChannelsDetails.TeamName[$j]}
            If ($TeamChannelsDetails.MembershipType[$j] -match "Private")
                {
                [string] $TeamPriviateChannelPermissionFile = "C:\GoDaddyTenant\Export\Teams\Permissions\TeamsPrivateChannelPermission_"+$TeamChannelsDetails.TeamGroupID[$j]+"_"+$TeamChannelsDetails[$j].DisplayName+".csv"
                $PrivateChannelPermission = Import-CSV  $TeamPriviateChannelPermissionFile
                Foreach ($UserPermission in $PrivateChannelPermission)
                    {
                    If ($UserPermission.user -match $SourceDomainName)
                        {
                        $dTargetUser = $UserPermission.user -replace  $SourceDomainName, $DestinationOnMicrosoftDomain
                        Write-Host $UserPermission.user adjusted to $dTargetUser -ForegroundColor Green
                        Write-Host Adding $dTargetUser as a member in Priviate Group $TeamChannelsDetails.DisplayName[$j]
                        Add-TeamChannelUser -GroupId $TargetGroupID.GroupID -DisplayName $TeamChannelsDetails.DisplayName[$j] -User $dTargetUser
                        If ($UserPermission.Role -eq "Owner")
                            {
                            Write-Host Elevating $dTargetUser as $UserPermission.Role in Priviate Group $TeamChannelsDetails.DisplayName[$j]
                            Start-Sleep -Seconds 30
                            Add-TeamChannelUser -GroupId $TargetGroupID.GroupID -DisplayName $TeamChannelsDetails.DisplayName[$j] -User $dTargetUser -Role Owner
                            }
                        }
                    }
                }
            } 																
        }
    Disconnect-MicrosoftTeams
    Disconnect-AzureAd
    }
Else
{
Write-Host InputFile Missing. Please run Teams Export Script to generate an input file with all required data from Source Tenant.
}

With this, Teams and Teams Channels are good to go.

Leave a Reply