Okay so this is probably one of the most basic things I’ve ever done/found within PowerShell, but it took me far too long to find this/something like this online and it has saved me countless hours. When I first started implementing Dial Plans/Direct Routing into Microsoft Teams, I was adding users numbers manually via PowerShell, this simple script will allow you to import a CSV file with every user and poll through them with a ForEach command.
Create the CSV
Simply create a CSV file with two column headers called ‘identity’ and ‘lineuri’ – Feel free to change these, but be sure to change the variables in the script below to match.
The PowerShell Command
Note
Your ‘Import-Csv’ command can include a full path in quotations such as “C:\PowerShellFolder\teamsusers.csv” if your CSV is in a different working folder than your PS window.
$UserList = Import-Csv teamsusers.csv
ForEach ($item in $UserList)
{
$Identity = $($item.identity)
$LineURI = $($item.lineuri)
Set-CsUser -Identity $identity -EnterpriseVoiceEnabled $true -HostedVoiceMail $true -OnPremLineURI $lineuri
}
Considerations
When adding the telephone numbers to the lineuri column, I tend to format the cells as Text and ensure that you use ‘tel:+44’ in each number rather than 0 as Teams only accepts E164 formats. You can use the Find & Replace function in Excel to find ‘0123’ and replace with ‘tel:+44123’ for example