Grant Dial Plans and Voice Policies to Multiple Users


Submitted by Scott Stubberfield and Nick Smith, Microsoft

 

In order to take advantage of Enterprise Voice (Microsoft’s implementation of Voice over IP) users need, among other things, to be assigned a dial plan and a voice policy. Dial plans and voice policies can easily be assigned to individual users by using Lync Server PowerShell. But is the same thing true when it comes to assigning dial plans and voice policies to multiple users?

 

As it turns out, it is true: all you have to do is save the required information (user identity, dial plan name, and voice policy name) in a comma-separated values file and then write a script that reads in that information and assigns the appropriate dial plans and policies.

 

Check that: you don’t have to write a script to do this. That’s because Scott Stubberfield and Nick Smith have already written such a script for you. Their script reads a comma-separated values file and then takes each user listed in that file and assigns the user the appropriate dial plan and voice policy. For example, suppose the first user in the file has the following property values:

 

SipUri

sip:seeuser11@p10.ca

DialPlan

SEDE.see.local

VoicePolicy

SeeUserVoicePolicy

 

For this first user (sip:seeuser11@p10.ca) the script will assign the dial plan listed in the DialPlan field and the voice policy listed in the VoicePolicy field. In effect, that means the script will run the following two commands:

 

Grant-CsDialPlan –Identity “sip:seeuser11@p10.ca” –PolicyName “SEDE.see.local”

 

Grant-CsVoicePolicy –Identity “sip:seeuser11@p10.ca” –PolicyName “SeeUserVoicePolicy”

 

And then the process will repeat with the next user in the file.

 

Here’s what the script looks like:

 

param( [string] $importfile = $(Read-Host -prompt `

    “Please enter a file name”))

$importedusers = Import-Csv $importfile

 

$transcriptname = “GrantPolicies” + (Get-Date `

    -Format s).Replace(“:”,”-“) +”.txt”

 

Start-Transcript $transcriptname

 

foreach ($importeduser in $importedusers)

    {

        Grant-CsDialPlan $importeduser.SipUri -PolicyName `
            $importeduser.DialPlan -Verbose

        Grant-CsVoicePolicy $importeduser.SipUri -PolicyName `
            $importeduser.VoicePolicy -Verbose

    }

Stop-Transcript

 

To make use of this script, copy the code to Notepad (or any other text editor), and then save the file using a .PS1 file extension (for example, C:ScriptsGrantDialPlanAndVoicePolicy.ps1). In addition, you must create a .CSV file similar to this, and save that file to your hard drive as well:

 

sipuri,dialplan,voicepolicy

sip:seeuser11@p10.ca,”SEDE.see.local”,”SeeUserVoicePolicy”

sip:seeuser12@p10.ca,”SEDE.see.local”,”SeeUserVoicePolicy”

sip:seeuser13@p10.ca,”SEDE.see.local”,”SeeUserVoicePolicy”

sip:seeuser14@p10.ca,”SEDE.see.local”,”SeeUserVoicePolicy”

sip:seeuser15@p10.ca,”SEDE.see.local”,”SeeUserVoicePolicy”

sip:seeuser16@p10.ca,”SEDE.see.local”,”SeeUserVoicePolicy”

sip:seeuser17@p10.ca,”SEDE.see.local”,”SeeUserVoicePolicy”

sip:seeuser18@p10.ca,”SEDE.see.local”,”SeeUserVoicePolicy”

sip:seeuser19@p10.ca,”SEDE.see.local”,”SeeUserVoicePolicy”

 

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:ScriptsGrantDialPlanAndVoicePolicy.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:ScriptsUsers.csv) and press ENTER; in turn, the script will read the data from the .CSV and then assign each user the appropriate dial plan and voice policy.

 

As if that isn’t enough, 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:

 

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

Comments (1)
  1. R. Treider says:

    The script does not work as advertised. The output errors are as follows.

    Policy ""Dial Plan"" is not a user policy. You can assign only a user policy to a specific user.

       + CategoryInfo          : InvalidOperation: (CN=USER-SPN:OCSADUserOrAppContact) [Grant-CsDia

      lPlan], ManagementException

       + FullyQualifiedErrorId : GrantPolicy,Microsoft.Rtc.Management.AD.Cmdlets.AssignOcsLocationProfileCmdlet

Comments are closed.

Skip to main content