Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 KB | None | 0 0
  1. $Users = Import-Csv -Path "c:\temp\users.csv"
  2.  
  3. foreach($user in $Users){
  4.  
  5. #Gets all unassigned number ranges. This needs to be done for each user in the foreach loop, as you keep changing the ranges.
  6. $UnasignedNumbers = Get-CsUnassignedNumber
  7.  
  8. #Need to loop through all ranges to find which one the users number belong to.
  9. foreach($Range in $UnasignedNumbers){
  10.  
  11. #From Get-CsUnassignedNumber you only get the first and last number of a range, not a number range readable in PowerShell.
  12. #We need to take away "tel:+47" from both start and end of the range.
  13. $StartRange = [int64]($Range.NumberRangeStart).Replace("tel:+47","")
  14. $EndRange = [int64]($Range.NumberRangeEnd).Replace("tel:+47","")
  15.  
  16. #Now we create a number range readable in PowerShell. $NumberRange contains all the numbers in the range, nto jsut start and end.
  17. $NumberRange = $StartRange..$EndRange
  18.  
  19. #We need to take away "tel:+47" from the users number.
  20. $StrippedNumber = ($User.LineURI).Replace("tel:+47","")
  21.  
  22. #If the users number is inside the currently processed number range we will go on at split the range its in.
  23. If($NumberRange -contains $StrippedNumber){
  24.  
  25. #The start of the range above the users number.
  26. $OneUp = "tel:+47"+([int64]$StrippedNumber+1)
  27.  
  28. #The end of the range below the users number.
  29. $OneDown = "tel:+47"+([int64]$StrippedNumber-1)
  30.  
  31. #Defiens the names of the two ranges. Use millisecon and a pause so you dont accedently give two ranges the same name.
  32. $LowRangeName = "Unasigned Numbers"+(Get-Date)+(Get-Date).Millisecond
  33. Start-Sleep -Seconds 1
  34. $HighRangeName = "Unasigned Numbers"+(Get-Date)+(Get-Date).Millisecond
  35.  
  36. #Removes the number range the users number is a part of.
  37. Remove-CsUnassignedNumber -Identity $range.Identity
  38.  
  39. #If the users number is the first one in the old range there is no need for creating a new range below the users number.
  40. #If its not the first number in the old range, you go on and create a new range below the users number.
  41. If($StrippedNumber -eq $StartRange){"Low range not needed!"}
  42. Else{New-CsUnassignedNumber -Identity "$LowRangeName" -AnnouncementName "Unassigned Number" -NumberRangeStart $Range.NumberRangeStart -NumberRangeEnd $OneDown}
  43.  
  44. #If the users number is the last one in the old range there is no need for creating a range above the users number.
  45. #If its not the last number in the old range, you go on and create a new range above the users number.
  46. If($StrippedNumber -eq $EndRange){"High range not needed!"}
  47. Else{New-CsUnassignedNumber -Identity "$HighRangeName" -AnnouncementName "Unassigned Number" -NumberRangeStart $OneUp -NumberRangeEnd $Range.NumberRangeEnd}
  48.  
  49.  
  50.  
  51. }
  52.  
  53. Else{"Not in range!"}
  54.  
  55. }
  56.  
  57. #Removes the number and disables enterprise voice for the user.
  58. Set-CsUser -Identity $user.UPNOld -EnterpriseVoiceEnabled $false -LineURI ""
  59.  
  60. #Adds the users phonenumber to the voice route that points incoming calls towards the SBC.
  61. $UserNumberForPattern = ($user.LineURI).Replace("tel:","")
  62. $OldNumberPattern = ((Get-CsVoiceRoute -Identity "Route to SBC").NumberPattern).trimend(')')
  63. $NewNumberPattaern = $OldNumberPattern+")|(\"+$UserNumberForPattern+"))"
  64. Set-CsVoiceRoute -Identity "Route to SBC" -NumberPattern $NewNumberPattaern
  65.  
  66. }
  67.  
  68.  
  69.  
  70.  
  71. #This part needs to be run with Skype Online PowerShell.
  72.  
  73. foreach($user in $users){
  74.  
  75.  
  76. #Adds the users number to a teams user, activates enterprice voice and sets various policies.
  77. Set-CsUser -Identity $user.UPNNew -EnterpriseVoiceEnabled $true -HostedVoiceMail $false -OnPremLineURI $user.LineURI
  78. Grant-CsOnlineVoiceRoutingPolicy -Identity $user.UPNNew -PolicyName Norway
  79. Grant-CsTeamsUpgradePolicy -Identity $user.UPNNew -PolicyName UpgradeToTeams
  80. Grant-CsTeamsCallingPolicy -Identity $user.UPNNew -PolicyName AllowCalling
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement