Microsoft Dynamics NAV 2013 Server Instance Tenants Discovery

Microsoft.Dynamics.Nav.2013.TenantDiscovery (Discovery)

This object discovery finds all tenants that are mounted to Microsoft Dynamics NAV 2013 Server instances.

Knowledge Base article:

Summary

This object discovery finds all tenants on Microsoft Dynamics NAV 2013 Server instances.

Element properties:

TargetMicrosoft.Dynamics.Nav.2013.ServerInstance
EnabledTrue
Frequency14400
RemotableFalse

Object Discovery Details:

Discovered Classes and their attribuets:

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.Windows.TimedPowerShell.DiscoveryProvider Microsoft.Dynamics.Nav.2013.DefaultAccount

Source Code:

<Discovery ID="Microsoft.Dynamics.Nav.2013.TenantDiscovery" Target="Microsoft.Dynamics.Nav.2013.ServerInstance" Enabled="true" ConfirmDelivery="false" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="Microsoft.Dynamics.Nav.2013.Tenant"/>
</DiscoveryTypes>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider" RunAs="Microsoft.Dynamics.Nav.2013.DefaultAccount">
<IntervalSeconds>14400</IntervalSeconds>
<SyncTime/>
<ScriptName>TenantDiscoveryScript.ps1</ScriptName>
<ScriptBody><Script># TenantsInstanceDiscoveryScript.ps1
# Copyright (c) Microsoft Corporation. All rights reserved.

param($target, $element, $principalName, $serverInstance, $serviceName)

# Generates a well formatted error details message, that helps troubleshooting
function Generate-ErrorDetails([string] $functionName)
{
[string] $errorRecord = [string]::Format("{0}`n{1}`n{2}`n{3}`n",$Error[0].Exception.Message,$Error[0].InvocationInfo.Line,$Error[0].InvocationInfo.PositionMessage,$Error[0].Exception)
if($Error[0].Exception.InnerException -ne $null) { $errorRecord = $errorRecord + $Error[0].Exception.InnerException }
$errorRecord = "`nScript: TenantsDiscoveryScript.ps1 `nFunctionName: " + $functionName + "`n`nError: " + $errorRecord
$Error[0].ErrorDetails = $errorRecord
}

# writes the last error record to the OperationManager eventlog
function Log-ScriptError()
{
# LogScriptEvent see http://msdn.microsoft.com/en-us/library/bb437630.aspx
[int] $severity = 1
[int] $eventId = 2013
[string] $eventSourceName = 'Microsoft Dynamics NAV 2013 Management Pack'

$scomapi.LogScriptEvent($eventSourceName, $eventId, $severity, $Error[0].ErrorDetails)
}

# main()
[Boolean] $noDiscData = 1
try
{
# Create the discovery data structure that we will return the discovered objects in
$scomapi = new-object -comObject "MOM.ScriptAPI"
$discData = $scomapi.CreateDiscoveryData(0, $element, $target)

# Get a list of all tenants, for a given server instance
$foundTenants = Get-NavTenant $serverInstance

# Create SCOM objects for the NAV Tenants
foreach ($tenant in $foundTenants)
{
# Create the Tenants object and initialize it with its key properties, no matter what.
$navTenant = $discData.CreateClassInstance("$MPElement[Name='Microsoft.Dynamics.Nav.2013.Tenant']$")
$navTenant.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $principalName)
$navTenant.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $tenant.Id)
$navTenant.AddProperty("$MPElement[Name='Service!Microsoft.SystemCenter.NTService']/ServiceName$", $serviceName)

# Reading the NAVTenant properties
$navTenant.AddProperty("$MPElement[Name='Microsoft.Dynamics.Nav.2013.Tenant']/TenantId$", $tenant.Id)
$navTenant.AddProperty("$MPElement[Name='Microsoft.Dynamics.Nav.2013.Tenant']/ServerInstance$", $serverInstance)
$navTenant.AddProperty("$MPElement[Name='Microsoft.Dynamics.Nav.2013.Tenant']/DatabaseServerAndInstance$", $tenant.DatabaseServer)
$navTenant.AddProperty("$MPElement[Name='Microsoft.Dynamics.Nav.2013.Tenant']/DatabaseName$", $tenant.DatabaseName)
$navTenant.AddProperty("$MPElement[Name='Microsoft.Dynamics.Nav.2013.Tenant']/AlternateTenantIds$", [String]::Join(", ", $tenant.AlternateId))
$navTenant.AddProperty("$MPElement[Name='Microsoft.Dynamics.Nav.2013.Tenant']/AllowApplicationDatabaseWrites$", $tenant.AllowAppDatabaseWrite)
$navTenant.AddProperty("$MPElement[Name='Microsoft.Dynamics.Nav.2013.Tenant']/NASServicesEnabled$", $tenant.NASServicesEnabled)
$navTenant.AddProperty("$MPElement[Name='Microsoft.Dynamics.Nav.2013.Tenant']/DefaultCompany$", $tenant.DefaultCompany)
$navTenant.AddProperty("$MPElement[Name='Microsoft.Dynamics.Nav.2013.Tenant']/DefaultTimeZone$", $tenant.DefaultTimeZone.DisplayName)
$navTenant.AddProperty("$MPElement[Name='Microsoft.Dynamics.Nav.2013.Tenant']/TenantState$", $tenant.State.ToString())

# add the WebServerInstance to the DiscoveryData object
$discData.AddInstance($navTenant)
$noDiscData = 0
}

$discData
}
catch
{
Generate-ErrorDetails "main"
Log-ScriptError
}
finally
{
# the last exception must be thrown to aleret the operator, but only if we don't have any discovery data to return.
if($noDiscData)
{
if ($Error.Count -gt 0)
{
throw $Error[0]
}
}
}
</Script></ScriptBody>
<SnapIns>
<SnapIn>Microsoft.Dynamics.Nav.Management</SnapIn>
</SnapIns>
<Parameters>
<Parameter>
<Name>Target</Name>
<Value>$Target/Id$</Value>
</Parameter>
<Parameter>
<Name>element</Name>
<Value>$MPElement$</Value>
</Parameter>
<Parameter>
<Name>principalName</Name>
<Value>$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Value>
</Parameter>
<Parameter>
<Name>serverInstance</Name>
<Value>$Target/Property[Type="Microsoft.Dynamics.Nav.2013.ServerInstance"]/ServerInstance$</Value>
</Parameter>
<Parameter>
<Name>serviceName</Name>
<Value>$Target/Property[Type="Service!Microsoft.SystemCenter.NTService']/ServiceName$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>300</TimeoutSeconds>
<StrictErrorHandling>true</StrictErrorHandling>
</DataSource>
</Discovery>