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:

function Enable-NAVServerInstancePortSharing
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory=$false, Position=0)]
        [System.String]
        $ServiceInstance = 'DynamicsNAV90'
    )
    write-Host -ForegroundColor Green "Enabling PortSharing for $ServiceInstance"
    Set-NAVServerInstance -ServerInstance $ServiceInstance -Stop -ErrorAction SilentlyContinue

    $null = sc.exe config (get-service NetTcpPortSharing).Name Start= Auto
    $null = Start-service NetTcpPortSharing
    
    $null = sc.exe config (get-service  "*$ServiceInstance*").Name depend= HTTP/NetTcpPortSharing
    
    Set-NAVServerInstance -ServerInstance $ServiceInstance -Start 
}

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: https://www.waldo.be/2015/08/07/port-sharing-with-nav-with-powershell/

4 comments

3 pings

Skip to comment form

    • Jan Hoek on August 7, 2015 at 8:02 am
    • Reply

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

      • waldo on August 24, 2015 at 1:27 pm
        Author

      Very true – but I like mine more 😉

  1. 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/

      • waldo on August 24, 2015 at 1:27 pm
        Author

      Thanks for the addition, man! 🙂

  1. […] Continue reading » […]

  2. […] 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. […] 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 to Port Sharing with NAV with PowerShell - Waldo's Blog - Microsoft Dynamics NAV Cancel reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.