private/Update-OnlinePhoneNumber.ps1
function Update-OnlinePhoneNumber { Param ([String]$ObjectId, [String]$PstnNumber) try { Write-OutputProxy " Try Setting OnlinePhoneNumber... " $number = Get-CsOnlineTelephoneNumber -TelephoneNumber $PstnNumber if ($number -eq $null) { Write-OutputProxy "[Failed]" Write-OutputProxy " Number not found." return $false } $location = $number.CityCode -Split "-" | Select-Object -Skip 1 -First 1 Set-MsolUser -ObjectId $ObjectId -UsageLocation $location Start-Sleep -Seconds 5 Sync-CsOnlineApplicationInstance -ObjectId $ObjectId Set-CsOnlineVoiceApplicationInstance -Identity $ObjectId -TelephoneNumber $PstnNumber -Force | Out-Null return $true } catch { Write-OutputProxy "[Failed]" Write-OutputProxy " $($_.Exception)" return $false } } |