Teams PowerShell Help
  • 07 Dec 2022
  • 5 Minutes to read
  • Dark
    Light
  • PDF

Teams PowerShell Help

  • Dark
    Light
  • PDF

Connect with PowerShell to Office 365

PowerShell can be used as an aid or complement to setting up the Teams DR service via the Teams Admin Center GUI.


Keep in mind that PowerShell is a very powerful tool and if used incorrectly it can easily and quickly cause a lot of damage, therefore the instructions should be followed carefully. And if you are going to do something else, be very sure of what you are doing.


NOTE: Make sure that the latest PowerShell version and latest addon Microsoft Teams Module are installed before proceeding.
We try to maintain the information to the latest but note that Microsoft can change commands at any time so please refer back to Microsoft.


See our Appendix for further how to information.


To connect to Office365 use:

Connect-MicrosoftTeams

Log in with an administrator account in Office 365 that is created online and has administrator rights to your domains.

You now have a PowerShell session running against Office 365 and can run all the commands needed to configure Direct Routing for telephony functionality in Microsoft Teams (plus everything else that's also related to Skype for Business Online and Microsoft Teams).


The session against Office 365 has an inactivity timer and when it is reached, a new session must be connected in a new PowerShell window, so it is not possible to continue in the same window and an error message is displayed.  Set up a new PowerShell session.
 

Control Gateway

Verify that the correct PSTN Gateway is set up with:

Get-CSOnlinePSTNGateway

t.ex.

Graphical user interface, text  Description automatically generated with medium confidence

NOTE: Note the customer's unique sbc and which port (5061)

Check Voice Routing Policy

Verify that there is a Voice Routing Policy needed for calling by running this command:

Get-CsOnlineVoiceRoutingPolicy

t.ex.

Text, timeline  Description automatically generated

NOTE: Note the name of the

It can be complimented with the command:

Get-CsOnlineVoiceRoute

Users

Users should have the correct licenses on them before adding them. Teams Telephony Standard

Add Users:

Set-CsPhoneNumberAssignment -Identity user@domain -PhoneNumber +46xxxxxx -PhoneNumberType "DirectRouting"

Grant-CsOnlineVoiceRoutingPolicy -Identity name@domain -PolicyName "Infracom-No Restrictions"

Check the user and user settings by running this:

Get-csonlineuser användare@domän.se | Out-File -FilePath C:\ Infracom.txt

This creates a txt file with all the data that the customer can send to us.

For further help always check our own manual regarding Teams Set-Up which also contains all the PowerShell commands needed to set everything up.

As well as the latest Microsoft documentation regarding commands.


Appendix  

Appendix 1 – PowerShell connection to Office 365

To do some of the configuration for Direct Routing telephony functionality in Microsoft Teams you need to run some PowerShell commands against Office 365, here is a detailed instruction on how to connect PowerShell against Office 365.

Note! Worth bearing in mind is that PowerShell is a very powerful tool and if used incorrectly it can very easily and quickly cause a lot of damage, therefore the instructions should be followed carefully. And if you are going to do something else, be very sure of what you are doing.

To get started there are two steps to go through, first you need Windows PowerShell version 3 or later installed on your computer. Then you need an add-on module in PowerShell for Microsoft Teams.

1. Check installed PowerShell version
Windows PowerShell 3.0 comes pre-installed in Windows 8 and later, and in Windows Server 2012 and later. So you have e.g. Windows 10, you can skip this step and go directly to the "Allow scripts to run" section.

In Windows 7, you may need to upgrade to Windows PowerShell 5.1 by following the instructions on this page: https://www.microsoft.com/en-us/download/details.aspx?id=54616

Check which version you have by starting PowerShell by searching for "PowerShell", or find the program in the Start menu. Right-click on Windows PowerShell and select Run as Administrator. Allow the program to start.

Graphical user interface, text, application  Description automatically generated

To check which version of Windows PowerShell is installed, type:

Get-Host | Select-Object Version

The result should be Version 5.x or higher. If not, follow the link on the previous page to install a later version. 

Example from Windows 10:

Graphical user interface, text, application  Description automatically generated

2. Allow script to run

To allow scripts to run, you need to set an Execution Policy. Run PowerShell as Administrator and type:

Set-ExecutionPolicy RemoteSigned -Force

Graphical user interface, text, application  Description automatically generated

If PowerShell is not running as Administrator, you will get this error message:

 A picture containing graphical user interface  Description automatically generated

Start PowerShell as Administrator and run the Set-ExecutionPolicy command again.

3. Install the Teams PowerShell module

Start a new Windows PowerShell window and type:

Install-Module MicrosoftTeams

On first installation you may get this question:

Text  Description automatically generated

Answer: A (Yes to everything)

Check which module version is used with:

Find-Module MicrosoftTeams

It should be version 3.1.0 or higher

4. Connect a PowerShell session to Office 365

Now that Windows PowerShell is version 5.1 or later and the MicrosoftTeams module is installed, it's time to connect a session to Office 365.

In PowerShell type :

Connect-MicrosoftTeams

Log in with an administrator account in Office 365 that is created online and has administrator rights to your domains.

You now have a PowerShell session running against Office 365 and can run all the commands needed to configure Direct Routing for telephony functionality in Microsoft Teams (plus everything else that's also related to Skype for Business Online and Microsoft Teams).

The session against Office 365 has an inactivity timer and when it is reached, a new session must be connected in a new PowerShell window, so it is not possible to continue in the same window and an error message is displayed.  Set up a new PowerShell session.

Appendix 2 - Common Errors


1. Pasted Command in PowerShell Gets Error


Make sure that all commands are written in one line, when you cut and paste commands it is easy to get errors that you don't get all the characters such as: " - " or that a line break with ">>" comes in between.

PowerShell is a powerful tool that can cause some problems and we recommend trying to learn it so that you can control your settings in Office 365 via PowerShell as well.
 

2. Running Scripts is Disabled

A screenshot of a computer  Description automatically generated with medium confidence

The error can occur, for example, when importing SkypeOnlineConnector. 

Make sure that you are running PowerShell as Administrator and that you have allowed script execution as described in section 2 of Appendix 1.

3. “Unable to Discover PowerShell Endpoint URI”

A picture containing text, indoor  Description automatically generated

The error occurs when trying to connect a PowerShell session against your Office365 with the wrong permissions.

Check that the account you are using to log in has administrator rights in Office 365 and that you may be coming from a Hybrid solution and need to use:

 -OverrideAdminDomain.

4 .“SBCA….. not configured for this tenant”

The error occurs when running the command: New-CsOnlinePSTNGateway

Check that the account you are logging in with really has administrator rights to all your domains, does the administrator have a Microsoft license? Run the command:

Get-CsTenant |select -ExpandProperty DOMAINURLMAP

 to see that your sbcaxxxx.pstnaccess.cellip.com domain is included in the answer.

 

Appendix 3 – Tips

1 . Update the Teams Module

Update the "GET" command via this in PowerShell:

Install-Module PowerShellGet -Force -AllowClobber

Look for the latest version:

Find-Module MicrosoftTeams 

And install the version shown via:    

Install-Module MicrosoftTeams -RequiredVersion "1.1.10-preview"

(Obs: 1.1.10 är ett exempel)

Otherwise, update the Teams Module by typing:

Update-Module MicrosoftTeams

2. Change or delete a user's number


Online users can only have one number and it may be necessary to change or delete a user's number.
To delete a number you can now either do it via the Teams Admin Center or through PowerShell via:

Remove-CsPhoneNumberAssignment -Identity user@domain -RemoveAll

This will disable Teams telephony as well as the user's PhoneNumberType.
Then run the same command to add a new user as found in point 5 with a new number for the user.

Also check if it is needed to remove licenses for the user that does not have a number anymore.
 


Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.