PowerShell Script To Migrate Users From Skype On Premises to Microsoft Teams

With the functionality available in Microsoft Teams, lot of organizations are focusing moving from an on-premises Skype for Business server to full Microsoft Teams Voice. This requires user accounts to be migrated to Teams and assigned Full Teams Only Mode.

I’ve put together a handy script to allow the migration from Skype to be user friendly and seamless from a admin perspective. The below script will give an export of all users and allow an admin to select one or more users and process them for migration. The script should be imported using “import-module TeamsMove.ps1” into the Skype for Business PowerShell Module and then the process can be kicked off by running the function “Move-ToTeams”. The script can be found on GitHub here.

Warning: This script may not run as expected in your environment and is used for illustration. It may need to be modified for your exact use case. Ensure you understand the steps and test before running in your environment.

##This function allows us to select users who are still homed in Skype for business
function move-toTeams-selectusers{
    $i = 1
    ##Allow selection of one or multiple users
    $users = (Get-CsUser -ResultSize unlimited | ?{$_.registrarPool -notlike $null} | Out-GridView -PassThru -Title "Select One or more users to migrate")
    
    ##Writing Progress to Screen
    Write-host you selected $users.count users

    ##check if it's array
    if($users -is [array]){
        foreach($User in $users){
        
             write-host Moving user $i of $users.count : $user.SipAddress

             Move-ToTeams-performMove $user
             $i++
        }
    }else{
            
            write-host Moving single user: $users.SipAddress
            Move-ToTeams-performMove $users

     }
}

function Move-ToTeams-performMove{
    <#
    .SYNOPSIS
    This function performs the move from Skype on Premises to Teams
    
    .DESCRIPTION
    This function accepts a user account and moves the user to Teams
    
    .PARAMETER useridentity
    Takes a user in for processing by the migration process
        
    .NOTES
    General notes
    #>
    param($useridentity)

    ##Removes conferencing policy from user account
     Grant-CsConferencingPolicy -PolicyName "No Dial-in" -Identity $useridentity.identity
     
     ##Create Dialog
     $a = new-object -comobject wscript.shell 

     ##Prompt for if calling policy should be enabled
     $intAnswer = $a.popup("Should " + $useridentity.sipaddress + " be enabled for outbound calling", 0,"Outbound Calls",4) 
    
    ##IF yes
    If ($intAnswer -eq 6) { 
        ##warn admin to ensure license is assigned
       $a.popup("Enabling Calling Policy for " + $useridentity.sipaddress + ", make sure they are licensed for Calling or this will fail!") 
        ##Enable outbound calling
        Set-CsUser -Identity $useridentity.identity -EnterpriseVoiceEnabled:$True
    }##Else no 
    else { 
        $a.popup("Removing Calling Policy from " + $useridentity.sipaddress + ", license can be removed if assigned") 
        ##Disable outbound calling
        Set-CsUser -Identity $useridentity.identity -EnterpriseVoiceEnabled:$False -Confirm:$false
    } 
  
    Try{
        ##Moves user to Teams
        Move-CsUser -Identity $UserIdentity.identity -Target sipfed.online.lync.com -MoveToTeams -Credential $credentials -HostedMigrationOverrideUrl $url -ErrorAction Stop -Confirm:$false
        write-host $UserIdentity.identity completed successfully -ForegroundColor Green

    }catch{
    #Catch and notify admin of error
    $ErrorMessage = $_.Exception.Message

    write-host Failed Migrating $useridentity.sip with error $ErrorMessage

    }

}


function Move-toTeams{



    ##Adding Teams endpoint URL
    $url="https://admin0e.online.lync.com/HostedMigration/hostedmigrationService.svc"
    
    ##If credentials dont exist, prompt for them
    if(!($credentials)){

        $credentials = Get-Credential -Message "Please enter credentials for an Office 365 admin with onmicrosoft UPN"

    }

    move-toTeams-selectusers

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s