PowerShell Script: Set Emergency Location for Unassigned Numbers in Teams

With the MicrosoftTeams PowerShell module version 5.4.0. Microsoft has added the possibility to set the emergency location on unassigned…

With the MicrosoftTeams PowerShell module version 5.4.0. Microsoft has added the possibility to set the emergency location on unassigned numbers.

Typically, whenever new numbers are bought or ported to Microsoft, an admin needs to specify the emergency address which should be assigned to the new numbers. In some cases, this process can fail which means that you could end up with user/subscriber numbers which don’t have an emergency address linked to it.

When you try to assign a number wich does not have an emergency location assigned, you’ll get an error, and you need to assign it again, including the -LocationId .

Set-CsPhoneNumberAssignment -PhoneNumber $number.TelephoneNumber -LocationId $matchingEmergencyLocationId

This is an operational risk since scripts that may have been working fine for months suddenly stop working properly for certain numbers and new users could end up without a phone number. To mitigate this risk, it’s best to make sure that all your numbers have an emergency address linked to them from the get-go.

Up until now, the only way to solve this issue was to create a case for Microsoft’s PSTN service desk team and ask them to assign a location Id to your unassigned number.

Previously, I’ve tackled this issue by making sure that my scripts checked if the number was assigned successfully. If it wasn’t I made sure that the number got assigned again including the location Id.

I also thought about creating a dummy user and a script which I could (mis)use. The script would get all unassigned numbers which don’t have a location Id assigned and processes all numbers after each other. Each time, the user’s usage location would be set to the country of the current number, the number would be assigned to the dummy user including the location Id and then unassigned again. However, that sounded like a waste of time to me, so I never pursued that idea.

The possibilities now are much better, and the recent update allowed me to create a simple script which makes sure that all unassigned numbers also have a location Id assigned.

Please note that the script assumes that there’s only ever 1 emergency address per city and that there’s at least 1 other number which already uses the correct emergency address.

If your environment does not meet the above criteria, you can’t use this script without tailoring it specifically to your needs. Use it at your own risk!

Also note that you need to clone or download the GitHub repo since it depends on other functions present in the repo.

I hope this helps you in streamlining and optimizing your phone number inventory.

Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
Hosted on GitHub Pages
Built with Hugo
Theme Stack designed by Jimmy