Share via

Provision Enterprise Voice using powershell initially works but after a few seconds some or all of the settings disappear

Simon Shaw 6 Reputation points
2022-04-14T09:27:10.347+00:00

Below is a simplified version of a script that I wrote that provisions 2 existing users for Enterprise Voice in teams with a calling plan (I have made minor changes to the script to hide confidential data).
The existing users already have an E1 license.
Sometimes the script works as expected, however most times I get an initial success, but when I look at the users a few minutes later, the EV settings have disappeared on 1 or both users.
I can find no consistency to predict the user that will lose its settings.
When I run a similar script for users that I am provisioning for Direct Route (i.e. they have no Calling Plan license), it runs consistently every time.
What am I doing incorrectly?

$skuIdPSTN = Get-AzureADSubscribedSku | Where-Object {$_.SkuPartNumber -eq 'MCOPSTN1'} | select SkuId
$skuIdMCOEV = Get-AzureADSubscribedSku | Where-Object {$_.SkuPartNumber -eq 'MCOEV'} | select SkuId

$AssignedLicenses = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
$LicenseMCOEV = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
$LicenseMCOEV.SkuId = $skuIdMCOEV.SkuId
$LicensePSTN = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
$LicensePSTN.SkuId = $skuIdPSTN.SkuId

$AssignedLicenses.AddLicenses = @($LicenseMCOEV, $LicensePSTN)
$AssignedLicenses.RemoveLicenses = @()

Set-AzureADUserLicense -ObjectId ******@contoso.com -AssignedLicenses $AssignedLicenses
Set-AzureADUserLicense -ObjectId ******@contoso.com -AssignedLicenses $AssignedLicenses

Start-Sleep -s 20

$cnt1 = 0
$sleep = 5
Set-CsOnlineVoiceUser -Identity "******@contoso.com" -TelephoneNumber +12122069936 -LocationID 726a2e5a-4f2d-4d91-a1d7-285c5be27d4c
$phoneNumber = Get-CsOnlineVoiceUser -Identity "******@contoso.com" | select Number, EnterpriseVoiceEnabled
while (($phoneNumber.Number -eq $null -or $phoneNumber.Number.Length -eq 0 -or $phoneNumber.EnterpriseVoiceEnabled -eq $false)  -and $cnt1 -lt 20)
{
    Start-Sleep -s $sleep
    Set-CsOnlineVoiceUser -Identity "******@contoso.com" -TelephoneNumber +12122069936 -LocationID 726a2e5a-4f2d-4d91-a1d7-285c5be27d4c
    $phoneNumber = Get-CsOnlineVoiceUser -Identity "******@contoso.com" | select Number, EnterpriseVoiceEnabled
    $cnt1++
    Write-Output "Set Number" + $cnt1
}
Write-Output "Alice Number Provisioned"

Grant-CsTeamsCallingPolicy -Identity "******@contoso.com" -PolicyName "AllowCalling"
Grant-CsTenantDialPlan -Identity "******@contoso.com" -PolicyName "MyDialPlan"
Write-Output "Alice Policies Provisioned"

$cnt1 = 0
Set-CsOnlineVoiceUser -Identity "******@contoso.com" -TelephoneNumber +12123382978 -LocationID 726a2e5a-4f2d-4d91-a1d7-285c5be27d4c
$phoneNumber = Get-CsOnlineVoiceUser -Identity "******@contoso.com" | select Number, EnterpriseVoiceEnabled
$sleep += $sleep
while (($phoneNumber.Number -eq $null -or $phoneNumber.Number.Length -eq 0 -or $phoneNumber.EnterpriseVoiceEnabled -eq $false)  -and $cnt1 -lt 20)
{
    Start-Sleep -s $sleep
    Set-CsOnlineVoiceUser -Identity "******@contoso.com" -TelephoneNumber +12123382978 -LocationID 726a2e5a-4f2d-4d91-a1d7-285c5be27d4c
    $phoneNumber = Get-CsOnlineVoiceUser -Identity "******@contoso.com" | select Number, EnterpriseVoiceEnabled
    $cnt1++
    Write-Output "Set Number" + $cnt1
}
Write-Output "Bob Number Provisioned"

Grant-CsTeamsCallingPolicy -Identity "******@contoso.com" -PolicyName "AllowCalling"
Grant-CsTenantDialPlan -Identity "bob@contos
Windows for business | Windows Server | User experience | PowerShell
Microsoft Teams | Microsoft Teams for business | Other
0 comments No comments

1 answer

Sort by: Most helpful
  1. Erwin Bierens 75 Reputation points MVP
    2023-01-12T07:50:22.5433333+00:00

    Is there something happening with your licenses in the background? Being synchronized from another (ERP) system that over rule your settings?

    If licenses get removed from the user, the enterpricevoice functionality is being removed automatically.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.