private/Update-PhoneNumber.ps1
function Update-PhoneNumber { Param ([String]$ObjectId, [String]$PstnNumber) try { Write-OutputProxy " Try Setting OnPremPhoneNumber... " Set-CsOnlineApplicationInstance -Identity $ObjectId -OnpremPhoneNumber $PstnNumber | Out-Null Sync-CsOnlineApplicationInstance -ObjectId $ObjectId Write-OutputProxy " [Done]" } catch [System.Management.Automation.RemoteException] { if ($_.Exception.Message -like "* is an online phone number*"){ Write-OutputProxy "[Failed]" Write-OutputProxy "Phone number is online phone number" return Update-OnlinePhoneNumber -ObjectId $ObjectId -PstnNumber $PstnNumber } else { Write-OutputProxy "[Failed]" Write-OutputProxy " $($_.Exception)" return $false } } catch { Write-OutputProxy "[Failed]" Write-OutputProxy " $($_.Exception)" return $false } return $true } |