Forum Discussion
Issue in script
Hello.
I've created some script to move users from SfB On Prem to Teams Only mode.
In script I create connection to SfB Online and O365. But after 1 hour script fails - something related to token, I think Azure AD one.
Error is in screenshot.
Here is my connection code part:
Import-Module "C:\\Program Files\\Common Files\\Skype for Business Online\\Modules\\SkypeOnlineConnector\\SkypeOnlineConnector.psd1"
$password = ConvertTo-SecureString “xxx” -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential (“xxx”, $password)
$global:session = New-CsOnlineSession -Credential $credential -OverrideAdminDomain qg1.onmicrosoft.com
Import-PSSession $session
Enable-CsOnlineSessionForReconnection
Connect-MsolService -Credential $Credential
How to resolve that issue because it's little annoying rerun script ebvery 1 hour 🙂 I setup that option Enable-CsOnlineSessionForReconnection but it doesn't help
5 Replies
- Sure! Please read this blog post:
https://ucstatus.com/2019/11/25/skypeonlineconnector-session-reconnection/amp/
Adam- msabatBrass Contributor
adam deltinger I have that command in my script. And in simple loop script it works.
But I think issue is with
Connect-MsolService
I think that token expires in 1 hour
- RuudGijsbersIron Contributor
Which command do you use for migrating the users to Teams? As of CU8 for SfB 2015 and SfB 2019, you can use the following command: Move-CsUser -Identity "someone@domain.com" -Target "sipfed.online.lync.com" -MoveToTeams -Credential $cred
That command doesn't need a connection to msolservice or Skype Online. Therefor you also won't run into the timing issue.
If you still need to use the Skype Online module, you could use something like this:
$StartDate = Get-Date foreach($user in $users){ $CurrentDate = Get-Date If ($CurrentDate -ge $StartDate.AddMinutes(45)){ $sfbSession = New-CsOnlineSession -Credential $cred Import-PSSession $sfbSession -AllowClobber -ErrorAction SilentlyContinue -WarningAction SilentlyContinue Enable-CsOnlineSessionForReconnection $StartDate = Get-Date } Grant-CsTeamsUpgradePolicy -identity $user.UPN -policyname UpgradeToTeams -confirm:$false }
To be on the safe side, it will reconnect 45 minutes after the first connection.