«

»

Print this Post

Get a specific Dynamics NAV Server Setting with PowerShell (a better Get-NAVServerConfiguration)

You might remember this blogpost: NAV 2013 R2: Powershell function to check if ServerInstance is Multitenant or not. It was a small tip on how to check a certain setting.

Recently I was working on a script, where I needed some other serversettings, and looking back on the way I was doing the above .. there had to be a better way. I mean .. looping all settings until I met the right one? Come on.. ;-).

Now, I don’t know if the following is “the best” method, but I find it at least somewhat better then above.

What is the problem?

Well, the output of the CmdLet “Get-NAVServerConfiguration” looks interesting and default, like:


It looks like the output is a number of objects with two properties: Key and value. But it isn’t. If you look at the members (with Get-Member), you actually have no decent properties at all :-/.

You might want to filter like this, but it doesn’t give you anything:

Get-NAVServerConfiguration -ServerInstance LIVE | where Key -eq "Multitenant"

There must be a reason for this. I can imagine in the background, it’s going to read the config.settings file in the server-folder.

There is a better way …

Now, you can look at it as xml as well, by using the “AsXML” parameter. When you do that, you can treat this output as xml, navigating the different nodes.. . For example, to fill an xml-variable with the output of this CmdLet, you can do like:

[xml]$myxml = Get-NAVServerConfiguration -ServerInstance LIVE -AsXml

And so you can look at it like xml .. not that I have too much experience in that 😉 .. but I noticed I could “browse” through the nodes by using intellisense. It didn’t take me much to figure out where everything was, quite an odd place, but hey .. Here, I found about the same output as the CmdLet itself:

$myxml.configuration.appSettings.add

But if you look at the member, you can actually see the “Key” and “Value” property:

$myxml.configuration.appSettings.add | Get-Member

So, I could definitely filter on this one with:

Get-NAVServerInstance | Get-NAVServerConfiguration2 | where Key -EQ "MultiTenant"

Knowing this, there are numerous ways to make it easy on you, and create a few new commandlets that can get you to the right properties easily. Below is an example on how to create your own “Get-NAVServerConfiguration”: 

Now, you can do stuff like:
  Get-NAVServerInstance | Get-NAVServerConfiguration2 | where Key -EQ "MultiTenant"

To get a list of all the “MultiTenant” settings of all the instances on your machine. In my opinion: now the CmdLet behaves like it’s supposed to 😉
Enjoy!

5.00 avg. rating (96% score) - 1 vote

Permanent link to this article: http://www.waldo.be/2015/02/10/get-a-specific-dynamics-nav-server-setting-with-powershell-a-better-get-navserverconfiguration/

2 comments

2 pings

  1. Peter

    Hi,
    as you are a powerShell Expert, do you know how to fix the error “This database is registered with several NAV Server instances. You must choose an instance to use before performing this activity. Do you want to continue?” that occurs to me if I call

    “#Export-NAVApplicationObject -Path ‘MyPath.txt’ -DatabaseName ‘databasename’ -DataBaseServer ‘databaseServer\nav’ -ExportTxtSkipUnlicensed -Force ”

    Is there anyway of selecting the instance?

    1. waldo

      I’m afraid not. You should try to find out why it says that (it will give you the same when exporting manually, most probably). As far as I know, there is no way around in PowerShell – as this is no PowerShell issue, but a finsql-issue.. .

  1. Dynamics NAV PowerShell: Creating an enhanced Get-NAVServerInstance function » waldo's blog

    […] are all aware that getting specific configuration properties isn’t as easy as it should be. I blogged about that here. Getting to specific settings in PowerShell should be easy. And what is easier then only having to […]

  2. Dynamics NAV PowerShell: Creating an enhanced Get-NAVServerInstance function - Microsoft Dynamics NAV Community

    […] are all aware that getting specific configuration properties isn’t as easy as it should be. I blogged about that here. Getting to specific settings in PowerShell should be easy. And what is easier then only having to […]

Leave a Reply

%d bloggers like this: