Inserting a PSTN usage into a Voice Policy

Voice Policies are assigned to users, and they control what a user is permitted to do in terms of voice functionality and calling. The “calling” part is determined by an ordered list of PSTN Usages within the Voice Policy.

Usages in VoicePolicy

The PSTN Usages are evaluated from top to bottom, until a call completes or the end of the list is reached.

If you’re using the Control Panel GUI and have just a few PSTN Usages and Voice Policies, it’s straight forward to edit this list. However, in the land of PowerShell, your only options are to remove a PSTN Usage, or to add one. The add function appends the PSTN Usage to the end of the list of usages, which isn’t ideal given that this is an ordered list.

I recent had to insert a new PSTN Usages into a large number of Voice Policies, and wrote this script to do that.

It’s straight forward to use. Create your new PSTN Usage, then run something like this:

Insert-PSTNUsage -CsVoicePolicy <VoicePolicy> -AddUsage <UsagetoAdd> -Priority <Priority>

where:

-CsVoicePolicy is the Voice Policy that you want to add the PSTN Usage to.

-AddUsage is the PSTN Usage that you want to add to the Voice Policy

-Priority is where the PSTN Usage should be added to the list of existing PSTN Usages. 0 is the start, and if you enter a value larger than the number of existing PSTN Usages, it’ll append to the end.

For example:

Insert-PSTNUsage -CsVoicePolicy VancouverStaff -AddUsage LongDistance -Priority 5 -verbose

This script returns no output to the console unless you use -verbose, in which case it will output the same information that’s also recorded to a log file:

Adding PstnUsage: LongDistance
To CsVoicePolicy: VancouverStaff
At priority: 2
Current Number of Usages: 6
Current Usages: zero One Two Three Four Five
Usages before insertion point: zero One
Usages after insertion point: Two Three Four Five
Restore Command: Set-CsVoicePolicy test -PstnUsages zero,One,Two,Three,Four,Five
Resulting in new usages: zero One LongDistance Two Three Four Five

  • The first three items are simply logging the parameters that you’ve provided.
  • Current Number of Usages is the number of PSTN Usages assigned to the Voice Policy before insertion.
  • Current Usages: a list of PSTN Usages assigned to the Voice Policy before insertion
  • Usages before insertion point and Usage after insertion point: Lists of usages before and after the spot where the new PSTN Usage will be inserted
  • Restore Command: this is a command that you can cut and paste into a PowerShell session to undo the Insert-CsPstnUsage command. The ability to back out your changes is something that I always like! (It might have wrapped in the above output, it’s not wrapped in the log file).
  • Resulting in new usages: this is a Get of the new list of PSTN Usages in the Voice Policy so that you can check your work.

I hope you find this useful, and I welcome your feedback!

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s