MSSQL on Windows: Data Source for Discover Installation Source (seed)
Microsoft.SQLServer.Windows.DataSource.LocalDiscoverySeed (DataSourceModuleType)
SQL Server Data Source for an installation seed for a Database Engine Discovery.
Element properties:
Member Modules:
Overrideable Parameters:
Source Code:
<DataSourceModuleType ID="Microsoft.SQLServer.Windows.DataSource.LocalDiscoverySeed" Accessibility="Public">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="PrincipalName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="IntervalSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="SyncTime" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" ParameterType="int" Selector="$Config/IntervalSeconds$"/>
<OverrideableParameter ID="TimeoutSeconds" ParameterType="int" Selector="$Config/TimeoutSeconds$"/>
<OverrideableParameter ID="SyncTime" ParameterType="string" Selector="$Config/SyncTime$"/>
</OverrideableParameters>
<ModuleImplementation>
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="System!System.Discovery.Scheduler">
<Scheduler>
<SimpleReccuringSchedule>
<Interval Unit="Seconds">$Config/IntervalSeconds$</Interval>
<SyncTime>$Config/SyncTime$</SyncTime>
</SimpleReccuringSchedule>
<ExcludeDates/>
</Scheduler>
</DataSource>
<ProbeAction ID="Script" TypeID="Windows!Microsoft.Windows.PowerShellDiscoveryProbe">
<ScriptName>DiscoverLocalDBEngineSeed.ps1</ScriptName>
<ScriptBody><Script>
param($principalName, $MapElement, $TargetID)
# CheckRegistryKeys.ps1
function CheckRegistryKeys
{
$paths = @('HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\110\Machines',
'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Microsoft SQL Server\110\Machines',
'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\120\Machines',
'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Microsoft SQL Server\120\Machines',
'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\130\Machines',
'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\140\Machines',
'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\150\Machines',
'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\160\Machines'
)
foreach($path in $paths)
{
$keyExists = Test-Path -Path $path -PathType Container -ErrorAction SilentlyContinue
if ($keyExists)
{
return $true
}
}
return $false
}# LogScriptEvents.ps1
$SCRIPT_EVENT_ID = 4221
$ERROR_EVENT_TYPE = 1
function LogErrorEvent($api, $publisher, $scriptName, [System.Management.Automation.ErrorRecord] $error)
{
$errMessage = "{0}`r`nCategory: {1}`r`nTarget: {2}" -f $error.Exception.Message, $error.CategoryInfo.Category, $error.CategoryInfo.TargetName
$api.LogScriptEvent("Publisher: $publisher`r`n$scriptName", $SCRIPT_EVENT_ID, $ERROR_EVENT_TYPE, $errMessage)
}
function LogErrorsEvent($api, $publisher, $scriptName, [System.Management.Automation.ErrorRecord[]] $errors)
{
$sb = New-Object -TypeName "System.Text.StringBuilder";
foreach($err in $errors)
{
[void]$sb.AppendFormat("`r`n{0}`r`nCategory: {1}`r`nTarget: {2}`r`n", $err.Exception.Message, $err.CategoryInfo.Category, $err.CategoryInfo.TargetName)
}
$api.LogScriptEvent("Publisher:$publisher`r`n$scriptName", $SCRIPT_EVENT_ID, $ERROR_EVENT_TYPE, $sb.ToString())
}# DiscoverLocalDBEngineSeed.ps1
$api = New-Object -ComObject "MOM.ScriptAPI"
$Error.Clear()
$sqlRegKeyExists = CheckRegistryKeys
$errorOccured = ($Error -ne $null) -and ($Error.Count -gt 0)
if (!$sqlRegKeyExists -and $errorOccured)
{
LogErrorsEvent $api "SQL Server Discovery MP Windows." "DiscoverLocalDBEngineSeed.ps1" $Error
}
$ErrorActionPreference = 'Stop'
$discoveryData = $api.CreateDiscoveryData(0, $MapElement, $TargetID)
if($sqlRegKeyExists)
{
$targetObj = $discoveryData.CreateClassInstance("$MPElement[Name='Microsoft.SQLServer.Windows.LocalDiscoverySeed']$")
$targetObj.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $principalName)
$targetObj.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "MSSQL on Windows: Discover Installation Source ($principalName)")
$discoveryData.AddInstance($targetObj)
$discoveryData
}
elseif(!$errorOccured){
$discoveryData
}</Script></ScriptBody>
<SnapIns/>
<Parameters>
<Parameter>
<Name>MapElement</Name>
<Value>$MPElement$</Value>
</Parameter>
<Parameter>
<Name>TargetID</Name>
<Value>$Target/Id$</Value>
</Parameter>
<Parameter>
<Name>PrincipalName</Name>
<Value>$Config/PrincipalName$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<StrictErrorHandling>true</StrictErrorHandling>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="Script">
<Node ID="DS"/>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>