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:

 

SipUri

sip:seeuser11@p10.ca

LineUri

tel:+10101

 

For this first user (sip:seeuser11@p10.ca) 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:seeuser11@p10.ca" –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"

 

Start-Transcript $transcriptname

 

foreach ($importeduser in $importedusers)

    {

        Set-CsUser $importeduser.SipUri -LineUri `
            $importeduser.LineUri –Verbose

    }

Stop-Transcript

 

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:\Scripts\AssignLineUris.ps1). In addition, you must create a .CSV file similar to this, and save that file to your hard drive as well:

 

SipUri,LineUri

sip:seeuser11@p10.ca,tel:+10101

sip:seeuser12@p10.ca,tel:+10102

sip:seeuser13@p10.ca,tel:+10103

sip:seeuser14@p10.ca,tel:+10104

sip:seeuser15@p10.ca,tel:+10105

sip:seeuser16@p10.ca,tel:+10106

sip:seeuser17@p10.ca,tel:+10107

sip:seeuser18@p10.ca,tel:+10108

sip:seeuser19@p10.ca,tel:+10109

 

To run the script from within the Lync Server Management Shell, simply type the full path to the .PS1 file and then press ENTER:

 

C:\Scripts\AssignLineUris.ps1

 

When the script starts, it will prompt you to enter the location of the .CSV file. Type in the file path (e.g., C:\Scripts\Users.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:

 

AssignLineUri2010-06-10T09-33-03.txt