This object discovery finds all Microsoft Dynamics NAV 2013 websites, hosted by IIS8.
Knowledge Base article:
Summary
This rule is run against all IIS 8 websites and discovers the subsets of websites on which Microsoft Dynamics NAV 2013 Web Server components are installed.
# writes the last error record a error 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'
# main()
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)
# Discovery of websites, isn't completed by IIS discovery, so the Path field isn't filled out yet.
if([System.String]::IsNullOrEmpty($Path))
{
return
}
# Read the web.config file
$webconfigFilePath = Join-Path $Path "web.config"
# return if the web.config file doesn't exist
if (!(Test-Path -PathType Leaf $webconfigFilePath))
{
return
}
$xmlDoc = [xml] (Get-Content $webconfigFilePath)
# Get the NAV section.
$navSettingsNode = $xmlDoc.configuration.DynamicsNAVSettings
# return if there is no NAV section
if ($navSettingsNode -eq $null)
{
return
}
# Create the Nav-WebSite object and initialize it with its key properties, in order to give the opsmgr the information that a NAV website was detected.
$navWebSite = $null
if ($iisVersion -eq '7')
{
$navWebSite = $DiscData.CreateClassInstance("$MPElement[Name='Microsoft.Dynamics.Nav.2013.IIS7.WebsiteConfiguration']$")
}
elseif ($iisVersion -eq '8')
{
$navWebSite = $DiscData.CreateClassInstance("$MPElement[Name='Microsoft.Dynamics.Nav.2013.IIS8.WebsiteConfiguration']$")
}
else
{
# return if the iisVersion isn't supported
return
}
# fill out the key properties
$navWebSite.AddProperty("$MPElement[Name='IISCommon!Microsoft.Windows.InternetInformationServices.WebSite']/SiteID$", $siteID)
$navWebSite.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $name)
$navWebSite.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $principalName)
# add the WebSite to the DiscoveryData object
$discData.AddInstance($navWebSite)
$discData
}
catch
{
Generate-ErrorDetails "main"
Log-ScriptError
}
finally
{
# the last exception must be thrown to aleret the operator.
if ($Error.Count -gt 0)
{
throw $Error[0]
}
} </Script></ScriptBody>
<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/Host/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Value>
</Parameter>
<Parameter>
<Name>Path</Name>
<Value>$Target/Property[Type="IISCommon!Microsoft.Windows.InternetInformationServices.WebSite"]/Path$</Value>
</Parameter>
<Parameter>
<Name>SiteID</Name>
<Value>$Target/Property[Type="IISCommon!Microsoft.Windows.InternetInformationServices.WebSite"]/SiteID$</Value>
</Parameter>
<Parameter>
<Name>Name</Name>
<Value>$Target/Property[Type="System!System.Entity"]/DisplayName$</Value>
</Parameter>
<Parameter>
<Name>IISVersion</Name>
<Value>8</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>300</TimeoutSeconds>
<StrictErrorHandling>true</StrictErrorHandling>
</DataSource>
</Discovery>