Quantcast
Channel: Microsoft Dynamics 365 Community
Viewing all articles
Browse latest Browse all 64797

Load NAV Service DLL for a specific Server Instance

$
0
0

Sometimes, you have multiple NAV Instances installed. When you have multiple installations, with different builds, you cannot use the PowerShell functions for each instance.

You could try loading the NavAdminTool.PS1 in the correct NST folder. However, this will probably not even work.

I have created a PowerShell function for this. This function was actually already posted in this post. But after receiving some feedback, about the title, I decided to create a separate post about it.

After editing the NavAdminTool.PS1, I found this:

$nstPath = "HKLM:\SOFTWARE\Microsoft\Microsoft Dynamics NAV\80\Service"
$managementDllPath = Join-Path (Get-ItemProperty -path $nstPath).Path '\Microsoft.Dynamics.Nav.Management.dll'
# First try to import the management module
Import-Module $managementDllPath -ErrorVariable errorVariable -ErrorAction SilentlyContinue

The PowerShell module will always read the registry for the installed version, and take that DLL…
So as we can read a bit further into the script, we can just Import-Module of the DLL directly. You will only not get a list of the imported commands.

Import-Module PATHTOMYNSTFOLDER\Microsoft.Dynamics.Nav.Management.dll

Or, if you want to be a bit more easy, you can you the function I created with a fellow colleague below:

function Load-NAVServiceDLL
{
    param([string] $ServerInstance)
    Remove-Module Microsoft.Dynamics.Nav.Management -Force -ErrorAction SilentlyContinue    

    $path = ([string](Get-WmiObject win32_service | ?{$_.Name.ToString().ToUpper() -like "*NavServer*$ServerInstance*"} | select PathName).PathName).ToUpper()
    $shortPath = $path.Substring(0,$path.IndexOf("EXE") + 3)
    if ($shortPath.StartsWith('"'))
    {
        $shortPath = $shortPath.Remove(0,1)
    }

    $PowerShellDLL = (Get-ChildItem -Path ((Get-ChildItem $ShortPath).Directory.FullName) "Microsoft.Dynamics.Nav.Management.DLL").FullName
    write-host "`nWelcome to the Server Admin Tool Shell!"
    write-host "For a complete list of Server cmdlets type`n"

    # Register Microsoft Dynamics NAV Management DLL
    Import-Module $PowerShellDLL -Force 

    write-host -fore Yellow "Get-Command -Module Microsoft.Dynamics.Nav.Management`n"

    # Print available commands
    Get-Command -Module Microsoft.Dynamics.Nav.Management 
}

This function can be used with partial NST names:

Load-NAVServiceDLL -ServerInstance PartOfInstance

1 side node though. You cannot run the Import-Module multiple times for the same module (or different version) during the same session. It appears that PowerShell keeps using the first imported version, and ignoring the latest you actually selected.


Viewing all articles
Browse latest Browse all 64797

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>