«

»

Print this Post

Port Sharing with NAV with PowerShell

You might have read my previous post about Dynamics NAV deployments and sharing ports. If you didn’t read the post, please do so, so you know how to do it in the first place.

Well, waldo wouldn’t be waldo if he wouldn’t try to find out how to do this with PowerShell ;-).

Sure, Port Sharing still isn’t really “encouraged” by Microsoft. But off the record (and with a really big disclaimer: I don’t support this either ;-)) – this works for our customers very well, and more importantly, it works for our internal development environments as well (+100 NST’s on one server) .. never had any problem related to this.

Problem

You can run about any dos command in powershell .. Sometimes it’s a real dos-exe, but most of the time, it’s a PowerShell alias. Problem in this case was that I needed to be able to use the command “sc”, but in PowerShell, this “sc” was an alias for “Set-Content” .. which doesn’t have anything remotely to do with the dos-version of the command (which is “configure a service”).

Solution

It was actually one of my developers that pointed me in the right direction. Why not just point to the exe, by not using “sc”, but “sc.exe”. Would it really be that simple? Uhm .. Yes .. actually it was. So I’ve spent some time in creating a function to cover about anything there is to cover for setting up “Port Sharing” for a certain ServerInstance. Here is the function:

As you can see, the commandline that I’m using is actually just the same as I was doing before .. but to be sure, I just enable the NetTcpPortSharing just in case, and restart the ServerInstance within the same function as well.

5.00 avg. rating (98% score) - 4 votes

Permanent link to this article: http://www.waldo.be/2015/08/07/port-sharing-with-nav-with-powershell/

4 comments

3 pings

Skip to comment form

  1. Jan Hoek

    cmd /c “{yourdoscommand}” is an alternative solution. But yours is more elegant, I suppose. 🙂

    1. waldo

      Very true – but I like mine more 😉

  2. Capone

    I just like to mention if you are using this on Azure together with the 1VM/2VM powershell script there are couple of more things you need to do in order for port sharing to work. I have done a blogpost about this: http://navfreak.com/2014/10/27/net-tcp-port-sharing-dynamics-nav-2015-and-azure/

    1. waldo

      Thanks for the addition, man! 🙂

  1. Port Sharing with NAV with PowerShell - Waldo's Blog - Microsoft Dynamics NAV

    […] Continue reading » […]

  2. Using NetTcpPortSharing for NAV Servers | Gunnar's Blog

    […] is needed.  Interestingly, after I had finished the task and was reading NAV blogs I saw that Waldo just published a powershell function on his blog to do just […]

  3. Net.TCP Port Sharing: Dynamics NAV 2015 and Azure | NAVfreak

    […] Update 2015-08-15: Waldo has now done a blog post on how to do port sharing with powershell which you can read here. […]

Leave a Reply

%d bloggers like this: