Do you check if you could move users from Skype for Business on-premises to online properly in bulk in Skype for Business Control Panel?
Could this script work again when you rerun it?
If every time it can only work fine for 15-20 users, then shows error message, it must be related to your script itself. As we are mainly responsible for general issue of Skype for Business, your script related to development is not in our scope. So, it’s hard for us to provide effective help on script.
Meanwhile, I found a slightly different script to move users as below. You could modify some parts of your script and check if it could work.
$cred=Get-Credential
$url="https://admin1a.online.lync.com/HostedMigration/hostedmigrationService.svc"
Move-CsUser -Identity username@contoso.com -Target sipfed.online.lync.com -Credential $cred -HostedMigrationOverrideUrl $url
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.