Lync / S4B redirect all calls from a give external number to a single number internally

I want to take all calls that arrive on a Lync 2010 / Skype for business site from a defined external number and send them to a single internal number, ignoring the originally called internal number.
One site on premise, one Lync 2010 pool with 99% of the users in it a and a migration Skype for Business 2015 pool with one test user.
LVL 16
Carol ChisholmAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Greg BessoIT Solutions EngineerCommented:
One server-side way to do this is to start using MSPL scripts on your Lync or SfB server. You can do this pretty easily actually. There are a few steps involved but basically it is...

1) Create a new network shared folder, you might have one already just for Lync. Either way, something like \\server\share\LyncFiles\CallForwarding.

2) Within this share, create a new file. It's a text file that you just rename to something like that.

3) For the contents that you need to put IN that file, look at this URL for example:

In that example, just look for the lines with toUri = ... and then fromUri = ... and the If statement below it. One way is to remove those sections and replace with something like...

toUri = GetUri(sipRequest.To);
toUserAtHost = Concatenate(GetUserName(toUri), "@", GetHostName(toUri));
telNum = GetUserName(toUri);

if ((ContainsString(toUserAtHost, "", true)) ){   Respond("302","Moved Temporarily","Contact=<>");    return;}
if ((ContainsString(toUserAtHost, "", true)) ){   Respond("302","Moved Temporarily","Contact=<>");    return;}

// at end have some way to exit back to Lync processes if not caught already...

4) Then once your file is setup, you need to create an application on your pool that uses it. Something like the following in the Lync PowerShell for example...
New-CsServerApplication –Identity "" –Uri -ScriptName "\\Server\Share\LyncFiles\CallForwarding\" –Critical $False –Enabled $False

5) Then you just go into the web admin console and enable that new server application you created. Click Topology > Server Application. Highlight this new CallForwarding item, and click Actions > Enable.

It's a lot to get familiar with if you haven't used this stuff before, but it's way easy once you review it and see that it's just a text file, with one line for each # you are redirecting, and voila. Hope that is helpful.
Greg BessoIT Solutions EngineerCommented:
OH and I should mention, whenever you want to choose to forward additional #'s you just edit the .am file and save/close it. It should then take effect quickly. You can stop/start that server application also to speed it up.
Carol ChisholmAuthor Commented:
Thanks I will read the link,
In your example you use

((ContainsString(toUserAtHost, "", true)) ){   Respond("302","Moved Temporarily","Contact=<>");    

I want to reroute  ALL incoming calls from a given external number independent of the destination. I'm not clear how that works in your example.
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

Carol ChisholmAuthor Commented:
Any perhaps I am not clear but this is no IM but Enterprise voice from a PSTN so there won't be any SIP information, just a number.
Carol ChisholmAuthor Commented:
I also have an Audiocodes gateway perhaps it would be easier to do it there?
Greg BessoIT Solutions EngineerCommented:
Yes sure thing. So the is how an incoming phone # to your internal users will be seen by the system. The phone # is where they are calling you from. Before it gets to your Lync users, that is how the # is seen as. SO if your Lync pool for users is and someone at +12125551212 is calling your EV #, and you want to instead have calls go to someone else, you just do something like...

if ((ContainsString(toUserAtHost, "", true)) ){   Respond("302","Moved Temporarily","Contact=<>");    return;}

It's weird looking, since you are redirecting the call to a Lync user so using their SIP address and not a phone #.
Carol ChisholmAuthor Commented:
What's an EV# ?

Seeems amazingly complicated... So my xml file should contain this?

<?xml version="1.0"?>
   <r:serverFilter roles="ALL"/>

   <!-- handle INVITE requests -->
   <r:requestFilter methodNames="INVITE"

   <!-- handle no response. -->
   <r:responseFilter reasonCodes="NONE"/>

   <!-- Script-only application. -->

     if (!sipRequest) {
     toUri = GetUri(sipRequest.To);
     fromUri = GetUri(sipRequest.From);

if ((ContainsString(toUserAtHost, "", true)) ){   Respond("302","Moved Temporarily","Contact=<>");    return;}

Greg BessoIT Solutions EngineerCommented:
EV means your enterprise voice phone #. I would say that you test this out in a test environment and get familiar with the basics, but I just uploaded my file that I used in the past. It has a couple of other statements you can ignore, just look at the one or two lines where it has the phone #'s that you would replace with yours.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Chat / IM

From novice to tech pro — start learning today.