«

»

Print this Post

NAV 2013 R2: Powershell function to check if ServerInstance is Multitenant or not

NAV 2013 R2: Powershell function to check if ServerInstance is Multitenant or not
1 vote, 5.00 avg. rating (98% score)

Hi, to end the year with – here is a small tip.

I’m working on improving the Backup/Restore procedure from this blogpost .. . While doing that, I was looking for a way to see whether my current instance was actually a Multitenant-server or not. In a way, I had to be able to read this configuration in powershell:


And I found a way .. by looping the output of the Get-NAVServerConfiguration commandlet. Here is the function:

function Get-NAVIsMultiTenantServerInstance
{
    [CmdletBinding()]
    param (
        [parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [String]$ServerInstance
    )
    PROCESS
    {   
        $CurrentServerConfig = Get-NAVServerConfiguration -ServerInstance $ServerInstance
        foreach ($CurrentServerConfigKey in $CurrentServerConfig)
        {
            if ($CurrentServerConfigKey.key -eq "Multitenant")
            {
                if ($CurrentServerConfigKey.Value -eq "false")
                {
                    return $false
                }
                else
                {
                    return $true    
                }
            }
        }
    }
} 

Don’t know if you like the function-name – but look at the function.. . May be there are smarter, better, more performant, more stable ways to do it .. if so .. please share :-).

In the mean time, this is how I can use the function (for example in my Backup-function):


Enjoy!

Permanent link to this article: http://www.waldo.be/2013/12/31/nav-2013-r2-powershell-function-to-check-if-serverinstance-is-multitenant-or-not/

3 comments

2 pings

  1. vytjak

    Hi Waldo, here’s a snippet to replace the loop to get the required value:

    (Get-NAVServerConfiguration -ServerInstance $serverInstance -AsXML).SelectSingleNode(‘configuration/appSettings/add[@key="Multitenant"]‘).value

    Enjoy the NY festivities :)

    1. waldo

      That is indeed a nicer way to replace the loop :-).
      Thanks for sharing!

  2. Microsoft Dynamics NAV

    I think this snippet is really works…..thanks for posting

  1. NAV 2013 R2: Powershell function to check if ServerInstance is Multitenant or not | Pardaan.com

    [...] Bron : Waldo’s Blog Lees meer… [...]

Leave a Reply