Submitted by Scott Stubberfield and Nick Smith, Microsoft
When you enable a user for Enterprise Voice (Microsoft’s implementation of Voice over IP) you also need to assign that user a line URI (i.e., a telephone number). Assign a line URI to one user? Here’s a command that can do that:
Set-CsUser –Identity “Ken Myer” –LineUri “tel:+14255551298”
Well, that looks easy enough. But what if you need to assign line URIs to 597 users? That looks like trouble.
But guess what: looks can be deceiving. Scott Stubberfield and Nick Smith have put together a script that can quickly and easily assign line URIs to any number of users, from one to, well, however many users you have in your organization. To do that, their script reads a comma-separated values file and then assigns each user listed in that file a line URI. For example, suppose the first user in the file has the following property values:
For this first user (sip:email@example.com) the script will assign the line URI listed in the LineUri field. That means that, effectively, the script will run the following command:
Set-CsUser –Identity “sip:firstname.lastname@example.org” –LineUri “tel:+10101”
After assigning the corresponding line URI to the first user listed in the file, the script will then proceed to assign the appropriate line URI to the next user listed in the file. Etc., etc.
The script itself looks a little like this:
param( [string] $importfile = $(Read-Host -prompt `
“Please enter a file name”))
$importedusers = Import-Csv $importfile
$transcriptname = “AssignLineUri” + (Get-Date `
-Format s).replace(“:”,”-“) +”.txt”
foreach ($importeduser in $importedusers)
Set-CsUser $importeduser.SipUri -LineUri `
To make use of this script, copy the code to your favorite text editor (e.g., Notepad), and then save the file using a .PS1 file extension (for example, C:ScriptsAssignLineUris.ps1). In addition, you must create a .CSV file similar to this, and save that file to your hard drive as well:
To run the script from within the Lync Server Management Shell, simply type the full path to the .PS1 file and then press ENTER:
When the script starts, it will prompt you to enter the location of the .CSV file. Type in the file path (e.g., C:ScriptsUsers.csv) and press ENTER; in turn, the script will read the data from the .CSV and then assign each user the appropriate line URI.
Incidentally, the script also maintains a detailed log of everything it does. That log will be stored in the current working directory, and will have a file name based on the current date and time. For example: