搜索发现提供程序

Microsoft.SharePoint.2016.SearchDiscoveryProvider (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsMicrosoft.SharePoint.Library.AdminAccount
OutputTypeSystem.Discovery.Data

Member Modules:

ID Module Type TypeId RunAs 
SearchDS DataSource Microsoft.SharePoint.2016.CommandExecuterDiscoveryDataSource Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$搜索发现提供程序: 间隔秒数间隔秒数:DiscoveryProvider 针对 SharePoint 搜索提供的属性。此发现将执行的频率(以秒为单位)。
SyncTimestring$Config/SyncTime$搜索发现提供程序: 同步时间搜索发现提供程序: 同步时间
TimeoutSecondsint$Config/TimeoutSeconds$搜索发现提供程序: 超时秒数搜索发现提供程序: 超时秒数
DebugTracebool$Config/DebugTrace$搜索发现提供程序: 调试跟踪搜索发现提供程序: 调试跟踪

Source Code:

<DataSourceModuleType ID="Microsoft.SharePoint.2016.SearchDiscoveryProvider" Accessibility="Internal" RunAs="MOSS!Microsoft.SharePoint.Library.AdminAccount">
<Configuration>
<xsd:element xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ComputerName" type="xsd:string"/>
<xsd:element xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="IntervalSeconds" type="xsd:integer"/>
<xsd:element xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="SyncTime" type="xsd:string"/>
<xsd:element xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="DebugTrace" type="xsd:boolean"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="SyncTime" Selector="$Config/SyncTime$" ParameterType="string"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
<OverrideableParameter ID="DebugTrace" Selector="$Config/DebugTrace$" ParameterType="bool"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="SearchDS" TypeID="Microsoft.SharePoint.2016.CommandExecuterDiscoveryDataSource">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime>$Config/SyncTime$</SyncTime>
<ApplicationName/>
<WorkingDirectory/>
<CommandLine>powershell.exe -NoLogo -NoProfile -Noninteractive "&amp; '$file/MOSSSharedServiceSearch.ps1$' '$MPElement$' '$Target/Id$' '$Config/ComputerName$' '$Config/DebugTrace$'"</CommandLine>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>MOSSStrings.ps1</Name>
<Contents><Script>$global:EventLog_Fail_Create_Discovery_Package = "Failed to create Discovery transmission package.";
$global:EventLog_Fail_Return_Discovery_Package = "Failed to return Discovery transmission package.";
$global:EventLog_Fail_Create_Discovery_ScriptAPI = "Failed to initiate MOM.ScriptAPI object.";
$global:EventLog_Fail_Create_Class = "Failed to create {0} class instance.";
$global:EventLog_Fail_Create_Relationship = "Failed to create {0} relationship instance.";
$global:EventLog_Fail_LoadBalancer_Operation = "Addresses for this application may not have been fetched yet.";

$global:EventLog_Exit_On_NonExist = "This machine does not have SharePoint installed."
$global:EventLog_Fail_On_Error = "{0} Discovery/Monitoring script continues under this error! ";
$global:EventLog_Exit_On_Error = "{0} Discovery/Monitoring script was terminated! ";

$global:EventLog_Format = @"
Current User: {0}
Current PID: {1}
InvocationInfo.MyCommand: {2}
InvocationInfo.ScriptLineNumber: {3}
InvocationInfo.OffsetInLine: {4}
InvocationInfo.ScriptName: {5}
InvocationInfo.Line: {6}
InvocationInfo.PositionMessage: {7}
InvocationInfo.InvocationName: {8}
InvocationInfo.PipelineLength: {9}
InvocationInfo.PipelinePosition: {10}
"@;

$global:EventLog_Template = "[{0} in Discovery/Monitoring script] {1} {2}";

$global:EventLog_Debug_StartedArgs = "[Debug] {0} Started. Args[]={1}, {2}, {3}, {4}.";
$global:EventLog_Debug_MajorServer = "[Debug] This is the major server detected by {0}.";

$global:EventLog_Fail_Identify_Farm = "Cannot identify which SharePoint farm this server is associated with. Check the management pack guide for troubleshooting information.";
$global:EventLog_Fail_Retrieve_Farm_And_Local = "Failed on retrieving information for SharePoint farm and Sharepoint local machine. Check the management pack guide for troubleshooting information.";
$global:EventLog_Fail_Retrieve_OM_Value = "Failed on retrieving values from SharePoint object model.";
$global:EventLog_Fail_Retrieve_Service = "Failed on retrieving {0} service from SharePoint farm {1}.";
$global:EventLog_Fail_Retrieve_Object = "Failed to find {0} in SharePoint object model.";

$global:DisplayName_ServerGroup = "Server Group";
$global:DisplayName_ServiceGroup = "Service Group";
$global:DisplayName_WebApplicationGroup = "Web Application Group";
$global:DisplayName_SharedServiceGroup = "Shared Service Group";
$global:DisplayName_SharedProxyGroup = "Shared Service Proxy Group";
$global:DisplayName_ProxyClient = "Proxy Client ({0})";
$global:DisplayName_TimerJobs = "Timer Jobs";
$global:DisplayName_HostCollection = "Host Collection";
$global:DisplayName_DatabaseCollection = "Database Collection";

$global:DisplayName_SPTrace = "SPTraceV4";
$global:DisplayName_WindowsTracingService = "SharePoint Tracing Service";
$global:DisplayName_AdminWord = " - Admin";

$global:EventLog_Fail_Retrieve_RegistryKey = "Failed to retrieve registry key {0}.";
$global:DisplayName_SiteCollection = "Site Collection";

$global:DisplayName_TimerJob = "Timer Job";

$global:DisplayName_Access_Page = "Access Page";
$global:DisplayName_Access_Page2 = "Access Page 2016";
$global:DisplayName_Excel_Page = "Excel Services Application Page";</Script></Contents>
</File>
<File>
<Name>MOSSDiscoveryLibrary.ps1</Name>
<Contents><Script>$error.Clear();
$ErrorActionPreference = "SilentlyContinue";

$global:EventObject = New-Object Diagnostics.EventLog
$global:EventObject.Source = "Operations Manager"

function global:Write-Event ([string] $LogContent, $LogType = [Diagnostics.EventLogEntryType]::Information)
{
if ($error)
{
$error.Clear()
$LogType = [Diagnostics.EventLogEntryType]::Error
}

$EventObject.WriteEntry($LogContent, $LogType)
}

function global:LogScriptTime($InvocationObj)
{
$dtEnd = [DateTime]::Now

$msg = @"
[Debug] {0} ended.
Current User: {1}
Current PID: {2}
start time: {3}
stop time: {4}
time taken: {5}
"@ -f $InvocationObj.MyCommand,
[Environment]::UserName,
$pid,
$dtStart,
$dtEnd,
(New-TimeSpan $dtStart $dtEnd).TotalMilliseconds

Write-Event $msg
}

.\MOSSStrings.ps1

$global:Arguments = $Args;

$global:Farm = $null;
$global:LocalServer = $null;
$global:DiscData = $null;
$global:Port = "_port";
$global:Http = "_http";

function global:Get-Farm()
{
if ($global:Farm -eq $null)
{

$global:Farm = [Microsoft.SharePoint.Administration.SPFarm]::Local;
}
}

function global:Get-LocalServer()
{
if ($global:LocalServer -eq $null)
{

$global:LocalServer = [Microsoft.SharePoint.Administration.SPServer]::Local;
}
}

function global:Get-ServiceProxy([string] $ClassType)
{
Get-Farm;
foreach ($ServiceProxy in $global:Farm.ServiceProxies)
{
if ($ClassType.ToLower() -eq $ServiceProxy.GetType().FullName.ToLower())
{
return $ServiceProxy;
}
}
return $null;
}

function global:Get-Service([string] $ClassType)
{
Get-Farm;
foreach ($Service in $global:Farm.Services)
{
if ($ClassType.ToLower() -eq $Service.GetType().FullName.ToLower())
{
return $Service;
}
}
return $null;
}

function global:Get-ServiceEx([string] $ClassType, [string] $Name)
{
Get-Farm;
foreach ($Service in $global:Farm.Services)
{
if ($ClassType.ToLower() -eq $ServiceInstance.GetType().FullName.ToLower())
{
if ($Name.ToLower() -eq $ServiceInstance.Name.ToLower())
{
return $ServiceInstance;
}
}
}
return $null;
}

function global:Get-ServiceInstance([string] $ClassType)
{
Get-LocalServer;

if (! $ClassType.EndsWith("Instance"))
{
$ClassType += "Instance";
}

foreach ($ServiceInstance in $global:LocalServer.ServiceInstances)
{
if ($ClassType.ToLower() -eq $ServiceInstance.GetType().FullName.ToLower())
{
return $ServiceInstance;
}
}
return $null;
}

function global:Get-ServiceInstanceEx([string] $ClassType, [string] $Name)
{
Get-LocalServer;

if (! $ClassType.EndsWith("Instance"))
{
$ClassType += "Instance";
}

foreach ($ServiceInstance in $global:LocalServer.ServiceInstances)
{
if ($ClassType.ToLower() -eq $ServiceInstance.GetType().FullName.ToLower())
{
if ($Name.ToLower() -eq $ServiceInstance.Name.ToLower())
{
return $ServiceInstance;
}
}
}
return $null;
}

function global:Create-DiscoveryData()
{
if ($global:DiscData -eq $null)
{
$global:DiscData = $global:MomScriptAPIObject.CreateDiscoveryData(0, $global:Arguments[0], $global:Arguments[1]);
Handle-Errors($global:EventLog_Fail_Create_Discovery_Package, $true, $false);

$global:HealthSvc = $global:DiscData.CreateClassInstance("$MPElement[Name='SC!Microsoft.SystemCenter.HealthService']$");
$global:HealthSvc.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $global:ComputerName);
Handle-Errors($global:EventLog_Fail_Create_Class -f "Microsoft.SystemCenter.HealthService");
}
return $global:DiscData;
}

function global:Deliver-DiscoveryData([Object] $DiscData)
{
$global:MomScriptAPIObject.Return($DiscData);
Handle-Errors($global:EventLog_Fail_Return_Discovery_Package, $true, $false);
$DiscData = $null;
}

function global:IsMainServer([System.Boolean] $UseLastServer)
{
$Servers = $global:Farm.Servers;

if ($UseLastServer)
{
$Count = $Servers.Count;
$ServerArray = new-object string[][] $Count,2;
$Index = 0;

foreach ($Server in $Servers)
{
$ServerArray[$Index][0] = $Server.Name;
$ServerArray[$Index++][1] = $Server.Role.ToString();
}

for ($Index--; $Index -ge 0; $Index--)
{

if ($ServerArray[$Index][1] -ne "Invalid")
{
return ($ServerArray[$Index][0] -eq $global:LocalServer.Name);
}
}
}
else
{
foreach ($Server in $Servers)
{

if ($Server.Role -ne "Invalid")
{
return ($Server.Name -eq $global:LocalServer.Name);
}
}
}

return $false;
}

function global:Release-Resources()
{
$global:HashData = $null;
$global:DiscData = $null;
$global:HealthSvc = $null;
$global:MomScriptAPIObject = $null;

$global:MOSSAssembly = $null;

$global:EventObject = $null;
$global:EventAssembly = $null;
}

function global:Handle-Errors([System.Object] $Arguments)
{
if (! $error)
{
return;
}

$ErrMsg = "";
$IsExit = $true;
$IsReturn = $true;
$IsLog = $true;

if ("System.String" -eq $Arguments.GetType().FullName)
{
$ErrMsg = $Arguments;
}
else
{
$ErrMsg = $Arguments[0];
$IsExit = $Arguments[1];
if ($Arguments.Count -gt 2)
{
$IsReturn = $Arguments[2];
}
if ("" -eq $ErrMsg)
{
$IsLog = $false;
}
}

if ($IsLog.Equals($true))
{
$ErrorString = "";
if ($IsExit.Equals($false))
{
$ErrorString = $global:EventLog_Fail_On_Error -f $ErrMsg;
}
else
{
$ErrorString = $global:EventLog_Exit_On_Error -f $ErrMsg;
}

$Exception = $error[$error.Count - 1];
if ($Exception.InvocationInfo -ne $null)
{
$ErrorString += ($global:EventLog_Format -f [Environment]::UserName, $pid, $Exception.InvocationInfo.MyCommand,
$Exception.InvocationInfo.ScriptLineNumber, $Exception.InvocationInfo.OffsetInLine, $Exception.InvocationInfo.ScriptName,
$Exception.InvocationInfo.Line, $Exception.InvocationInfo.PositionMessage, $Exception.InvocationInfo.InvocationName,
$Exception.InvocationInfo.PipelineLength, $Exception.InvocationInfo.PipelinePosition);
}

if ($null -ne $Exception.Exception)
{
$Exception = $Exception.Exception;
}
$InnerException = $Exception;
if ($null -ne $Exception.InnerException)
{
$InnerException = $Exception.InnerException;
}

$global:EventObject.WriteEntry(($global:EventLog_Template -f $InnerException.GetType().FullName, $ErrorString, $Exception.Message), [System.Diagnostics.EventLogEntryType]::Error);
}

if ($IsExit.Equals($true))
{
if ($IsReturn.Equals($true))
{
Deliver-DiscoveryData($global:DiscData);
}
Release-Resources;
break;
}

$error.Clear();
}

function global:GetDebugSetting($DebugTrace)
{

if ($DebugTrace.ToUpper() -eq "TRUE")
{
$global:Debug = $True;
}
else
{
$global:Debug = $False;
}

}

$global:MomScriptAPIObject = new-object -comObject "MOM.ScriptAPI";
Handle-Errors($global:EventLog_Fail_Create_Discovery_ScriptAPI, $true, $false);

$global:MOSSAssembly = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint");
if ($null -eq $global:MOSSAssembly)
{
throw $global:EventLog_Exit_On_NonExist;
}
Handle-Errors("", $true, $false);

if ($MOSSAssembly.GetName().Version.Major -ne 16)
{
Release-Resources;
break;
}

function global:Get-SharePointExtensionsLocation()
{
$Location = "";

$LM = [Microsoft.Win32.Registry]::LocalMachine;
$Key = $LM.OpenSubKey("SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\16.0");
if ($null -eq $Key)
{
Write-Event(($global:EventLog_Fail_Retrieve_RegistryKey -f "SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\16.0"), [System.Diagnostics.EventLogEntryType]::Error);
}
else
{
$Location = $Key.GetValue("Location", "");
if ("" -eq $Location)
{
Write-Event(($global:EventLog_Fail_Retrieve_RegistryKey -f "SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\16.0\Location"), [System.Diagnostics.EventLogEntryType]::Error);
}
}
return $Location;
}

function global:IsServingAsWebServer()
{
if (([Microsoft.SharePoint.Administration.SPServerRole]::SingleServer -eq $global:LocalServer.Role) -or ([Microsoft.SharePoint.Administration.SPServerRole]::WebFrontEnd -eq $global:LocalServer.Role))
{
return $true;
}
elseif ([Microsoft.SharePoint.Administration.SPServerRole]::Application -eq $global:LocalServer.Role)
{
$WebServiceInstance = [Microsoft.SharePoint.Administration.SPWebServiceInstance]::LocalContent;
if (($null -ne $WebServiceInstance) -and ([Microsoft.SharePoint.Administration.SPObjectStatus]::Online -eq $WebServiceInstance.Status))
{
return $true;
}
}

return $false;
}

function global:Get-ServiceTimerJobs([string] $ServiceTypeName)
{
$Service = Get-Service($ServiceTypeName);
if ($null -eq $Service)
{
return $null;
}

return $Service.JobDefinitions;
}

function global:IsLocalTimerServiceRunning()
{
$ServiceInstance = Get-ServiceInstance($global:SPTimer);

if (($null -ne $ServiceInstance) -and ([Microsoft.SharePoint.Administration.SPObjectStatus]::Online -eq $ServiceInstance.Status))
{
return $true;
}

return $false;
}

function global:Create-SiteCollectionEx([Object] $WebApp)
{
$DefaultZone = [Microsoft.SharePoint.Administration.SPUrlZone]::Default;
$AppPath = $WebApp.IisSettings[$DefaultZone].Path.ToString();
$Uri = $WebApp.GetResponseUri($DefaultZone).AbsoluteUri;
$Authentication = $WebApp.IisSettings[$DefaultZone].AuthenticationMode.ToString();
$WebAppName = $WebApp.DisplayName;

$SiteCollection = $global:DiscData.CreateClassInstance("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPWebApplication.SPSiteCollection']$");
$SiteCollection.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $global:DisplayName_SiteCollection);
$SiteCollection.AddProperty("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPWebApplication.SPSiteCollection']/FarmID$", $global:FarmID);
$SiteCollection.AddProperty("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPWebApplication.SPSiteCollection']/FarmName$", $global:FarmName);
$SiteCollection.AddProperty("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPWebApplication.SPSiteCollection']/AppPath$", $AppPath);
$global:DiscData.AddInstance($SiteCollection);
Handle-Errors(($global:EventLog_Fail_Create_Class -f "SPWebApplication.SPSiteCollection"), $false);

$WebApplication = $global:DiscData.CreateClassInstance("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPWebApplication']$");
$WebApplication.AddProperty("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPWebApplication']/FarmID$", $global:FarmID);
$WebApplication.AddProperty("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPWebApplication']/FarmName$", $global:FarmName);
$WebApplication.AddProperty("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPWebApplication']/AppPath$", $AppPath);
$WebApplication.AddProperty("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPWebApplication']/ResponseUri$", $Uri);
$WebApplication.AddProperty("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPWebApplication']/Name$", $WebAppName);
$WebApplication.AddProperty("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPWebApplication']/Authentication$", $Authentication);
$WebApplication.AddProperty("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPWebApplication']/AppPool$", $WebApp.ApplicationPool.Name);
$WebApplication.AddProperty("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPWebApplication']/AppUser$", $WebApp.ApplicationPool.Username);

$global:DiscData.AddInstance($WebApplication);
Handle-Errors(($global:EventLog_Fail_Create_Class -f "SPWebApplication"), $false);

$WebAppSiteCollRel = $global:DiscData.CreateRelationshipInstance("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPWebApplication.Contains.SPSiteCollection']$");
$WebAppSiteCollRel.Source = $WebApplication;
$WebAppSiteCollRel.Target = $SiteCollection;
$global:DiscData.AddInstance($WebAppSiteCollRel);
Handle-Errors(($global:EventLog_Fail_Create_Relationship -f "SPWebApplication.Contains.SPSiteCollection"), $false);

return $SiteCollection;
}

$global:MOSSConfig = "Microsoft.SharePoint.Administration.SPConfigurationDatabase";
$global:MOSSAdmin = "Microsoft.SharePoint.Administration.SPWebService";
$global:SPAdmin = "Microsoft.SharePoint.Administration.SPAdministrationService";
$global:SPSearch = "Microsoft.SharePoint.Search.Administration.SPSearchService";
$global:SPIncomingMail = "Microsoft.SharePoint.Administration.SPIncomingEmailService";
$global:SPHelpSearch = "Microsoft.SharePoint.Search.Administration.SPSearchService";
$global:SPTimer = "Microsoft.SharePoint.Administration.SPTimerService";
$global:SPWebApp = "Microsoft.SharePoint.Administration.SPWebService";
$global:SPUserCode = "Microsoft.SharePoint.Administration.SPUserCodeService";
$global:SPDatabase = "Microsoft.SharePoint.Administration.SPDatabaseService";

$global:SPTopology = "Microsoft.SharePoint.SPTopologyWebService";
$global:SPUsage = "Microsoft.SharePoint.Administration.SPUsageService";
$global:SPBDC = "Microsoft.SharePoint.BusinessData.SharedService.BdcService";
$global:SPSecurityToken = "Microsoft.SharePoint.Administration.Claims.SPSecurityTokenService";

$global:OSForms = "Microsoft.Office.InfoPath.Server.Administration.FormsService";
$global:DCLoadBalancer = "Microsoft.Office.Server.Conversions.LoadBalancerService";
$global:DCLauncher = "Microsoft.Office.Server.Conversions.LauncherService";

$global:SSAccess = "Microsoft.Office.Access.Server.MossHost.AccessServerWebService";
$global:SSAccess2 = "Microsoft.Office.Access.Services.MossHost.AccessServicesWebService";
$global:SSPerfPoint = "Microsoft.PerformancePoint.Scorecards.BIMonitoringService";
$global:SSSecureStore = "Microsoft.Office.SecureStoreService.Server.SecureStoreService";
$global:SSTaxonomy = "Microsoft.SharePoint.Taxonomy.MetadataWebService";
$global:SSUserProfile = "Microsoft.Office.Server.Administration.UserProfileService";
$global:SSVisio = "Microsoft.Office.Visio.Server.Administration.VisioGraphicsService";

$global:SSWordSvc = "Microsoft.Office.Word.Server.Service.WordService";
$global:SSTranslation = "Microsoft.Office.TranslationServices.TranslationService";

$global:MySiteTemplate = "SPSMSITEHOST";

$global:PathAccessPage = "template\layouts\accsrv\modifyapplication.aspx";
$global:PathAccessPage2 = "template\layouts\accsvc\openinaccess.aspx";
</Script></Contents>
</File>
<File>
<Name>MOSSSharedServiceSearch.ps1</Name>
<Contents><Script>.\MOSSDiscoveryLibrary.ps1 $Args[0] $Args[1]

$SearchServiceClassName = "microsoft.office.server.search.administration.searchqueryandsitesettingsservice"
$HostControllerServiceName = "Search Host Controller Service"
$computerName = $Args[2]
Get-Farm
Get-LocalServer
$DiscoveryData = Create-DiscoveryData

if ($null -ne $global:Farm)
{

$global:FarmID = $global:Farm.Id.toString()
$global:FarmName = $global:Farm.Name
$InstSystemBase = $DiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.SharePoint.2016.SPSharedServiceGroup']$")
$InstSystemBase.AddProperty("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPSharedServiceGroup']/FarmID$",$global:FarmID)
$InstSystemBase.AddProperty("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPSharedServiceGroup']/FarmName$",$global:FarmName)
foreach ($Service in $global:Farm.Services)
{
if (($null -ne $Service) -and $SearchServiceClassName -eq $Service.GetType().FullName.ToLower() -and ([Microsoft.SharePoint.Administration.SPObjectStatus]::Online -eq $Service.Status))
{

$InstSystemSearchBase = $DiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.SharePoint.2016.SPSharedService.Search']$")
$InstSystemSearchBase.AddProperty("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPService']/FarmID$", $global:FarmID)
$InstSystemSearchBase.AddProperty("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPService']/FarmName$", $global:FarmName)
$InstSystemSearchBase.AddProperty("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPService']/ServiceID$", $Service.Id.ToString())
$InstSystemSearchBase.AddProperty("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPService']/TypeName$", $Service.GetType().FullName)
$InstSystemSearchBase.AddProperty("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPService']/NotShared$", "False")
$InstSystemSearchBase.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$",$Service.TypeName)
$DiscoveryData.AddInstance($InstSystemSearchBase);
Handle-Errors(($global:EventLog_Fail_Create_Class -f "SPSharedService.Search"), $false);

$Rel = $DiscoveryData.CreateRelationshipInstance("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPSharedServiceGroup.Contains.SPSharedService']$")
$Rel.Source = $InstSystemBase
$Rel.Target = $InstSystemSearchBase
$DiscoveryData.AddInstance($Rel);
Handle-Errors(($global:EventLog_Fail_Create_Relationship -f "SPSharedServiceGroup.Contains.SPSharedService"), $false);

$InstSystemInstance = $DiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.SharePoint.2016.SPSharedServiceApplication.SearchGroup']$")
$InstSystemInstance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "Search Service Application Group")
$InstSystemInstance.AddProperty("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPSharedServiceApplication']/FarmID$", $global:FarmID)
$InstSystemInstance.AddProperty("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPSharedServiceApplication']/FarmName$", $global:FarmName)
$InstSystemInstance.AddProperty("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPSharedServiceApplication']/ServiceApplicationID$", "None")
$InstSystemInstance.AddProperty("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPSharedServiceApplication']/TypeName$", "SearchGroup")
$DiscoveryData.AddInstance($InstSystemInstance);
Handle-Errors(($global:EventLog_Fail_Create_Class -f "SPSharedServiceApplication.SearchGroup"), $false);

$Rel1 = $DiscoveryData.CreateRelationshipInstance("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPSharedService.Contains.SPSharedServiceApplication']$")
$Rel1.Source = $InstSystemSearchBase
$Rel1.Target = $InstSystemInstance
$DiscoveryData.AddInstance($Rel1);
Handle-Errors(($global:EventLog_Fail_Create_Relationship -f "SPSharedService.Contains.SPSharedServiceApplication"), $false);

$HostControllerGroup = $DiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.SharePoint.2016.SPSharedServiceApplication.HostControllerGroup']$")
$HostControllerGroup.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "Host Controller Group - $global:FarmID")
$HostControllerGroup.AddProperty("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPSharedServiceApplication']/FarmID$", $global:FarmID)
$HostControllerGroup.AddProperty("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPSharedServiceApplication']/FarmName$", $global:FarmName)
$HostControllerGroup.AddProperty("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPSharedServiceApplication']/ServiceApplicationID$", "None")
$HostControllerGroup.AddProperty("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPSharedServiceApplication']/TypeName$", "Host Controller Group")
$DiscoveryData.AddInstance($HostControllerGroup);
Handle-Errors(($global:EventLog_Fail_Create_Class -f "SPSharedServiceApplication.HostControllerGroup"), $false);

$Rel2 = $DiscoveryData.CreateRelationshipInstance("$MPElement[Name='MOSS!Microsoft.SharePoint.Library.SPSharedService.Contains.SPSharedServiceApplication']$")
$Rel2.Source = $InstSystemSearchBase
$Rel2.Target = $HostControllerGroup
$DiscoveryData.AddInstance($Rel2);
Handle-Errors(($global:EventLog_Fail_Create_Relationship -f "SPSharedService.Contains.SPSharedServiceApplication"), $false);
$Servers = $global:Farm.Servers
foreach ($Server in $Servers)
{
$Runtime = ($Server.ServiceInstances)|where {$_.TypeName -eq $HostControllerServiceName}
if ($null -ne $Runtime -and $Runtime.status -eq "Online")
{
if ($computerName.StartsWith($Server.Name, "InvariantCultureIgnoreCase"))
{
$HostController = $DiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.SharePoint.2016.HostController']$")
$HostController.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $computerName)
$HostController.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "Host Controller - $computerName")
$DiscoveryData.AddInstance($HostController);
Handle-Errors(($global:EventLog_Fail_Create_Class -f "SharePoint.2016.HostController"), $false);

$Rel3 = $DiscoveryData.CreateRelationshipInstance("$MPElement[Name='Microsoft.SharePoint.2016.Relationship.HostControllerGroupMembership']$")
$Rel3.Source = $HostControllerGroup
$Rel3.Target = $HostController
$DiscoveryData.AddInstance($Rel3);
Handle-Errors(($global:EventLog_Fail_Create_Relationship -f "Relationship.HostControllerGroupMembership"), $false);
}
}
}

foreach ($Ssa in $Service.Applications)
{
$SsaId = $Ssa.id.toString()

$InstSystem = $DiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.SharePoint.2016.SearchApplication']$")
$InstSystem.AddProperty("$MPElement[Name='Microsoft.SharePoint.2016.SearchApplication']/FarmID$", $global:FarmID)
$InstSystem.AddProperty("$MPElement[Name='Microsoft.SharePoint.2016.SearchApplication']/FarmName$", $global:FarmName)
$InstSystem.AddProperty("$MPElement[Name='Microsoft.SharePoint.2016.SearchApplication']/System$", $Ssa.id.toString())
$InstSystem.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $Ssa.DisplayName)
$DiscoveryData.AddInstance($InstSystem);
Handle-Errors(($global:EventLog_Fail_Create_Class -f "SearchApplication"), $false);

$Rel2 = $DiscoveryData.CreateRelationshipInstance("$MPElement[Name='Microsoft.SharePoint.2016.Relationship.SearchApplicationGroupMembership']$")
$Rel2.Source = $InstSystemInstance
$Rel2.Target = $InstSystem
$DiscoveryData.AddInstance($Rel2);
Handle-Errors(($global:EventLog_Fail_Create_Relationship -f "Relationship.SearchApplicationGroupMembership"), $false);
foreach ($SearchComponent in $Ssa.ActiveTopology.GetComponents())
{
if ($computerName.StartsWith($SearchComponent.ServerName, "InvariantCultureIgnoreCase"))
{
$GroupName = "Unknown Group"
$StrComponentClass = "`$MPElement[Name='Microsoft.SharePoint.2016.SearchComponent']$"

if ($SearchComponent.getType().toString() -eq "Microsoft.Office.Server.Search.Administration.Topology.CrawlComponent")
{
$StrComponentClass = "`$MPElement[Name='Microsoft.SharePoint.2016.CrawlComponent']$"
$GroupName = "Crawl Component Group "
}
elseif ($SearchComponent.getType().toString() -eq "Microsoft.Office.Server.Search.Administration.Topology.ContentProcessingComponent")
{
$StrComponentClass = "`$MPElement[Name='Microsoft.SharePoint.2016.ContentProcessingComponent']$"
$GroupName = "Content Processing Component Group "
}
elseif ($SearchComponent.getType().toString() -eq "Microsoft.Office.Server.Search.Administration.Topology.IndexComponent")
{
$StrComponentClass = "`$MPElement[Name='Microsoft.SharePoint.2016.IndexComponent']$"
$GroupName = "Index Component Group "
}
elseif ($SearchComponent.getType().toString() -eq "Microsoft.Office.Server.Search.Administration.Topology.AdminComponent")
{
$StrComponentClass = "`$MPElement[Name='Microsoft.SharePoint.2016.AdminComponent']$"
$GroupName = "Admin Component Group "
}
elseif ($SearchComponent.getType().toString() -eq "Microsoft.Office.Server.Search.Administration.Topology.QueryProcessingComponent")
{
$StrComponentClass = "`$MPElement[Name='Microsoft.SharePoint.2016.QueryProcessingComponent']$"
$GroupName = "Query Processing Component Group "
}
elseif ($SearchComponent.getType().toString() -eq "Microsoft.Office.Server.Search.Administration.Topology.AnalyticsProcessingComponent")
{
$StrComponentClass = "`$MPElement[Name='Microsoft.SharePoint.2016.AnalyticsProcessingComponent']$"
$GroupName = "Analytics Processing Component Group "
}
$GroupFullName = $GroupName +"-" + $SsaId;
$InstComponentGroup = $DiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.SharePoint.2016.Group.SearchComponents']$")
$InstComponentGroup.AddProperty("$MPElement[Name='Microsoft.SharePoint.2016.Group.SearchComponents']/FarmID$", $global:FarmID)
$InstComponentGroup.AddProperty("$MPElement[Name='Microsoft.SharePoint.2016.Group.SearchComponents']/FarmName$", $global:FarmName)
$InstComponentGroup.AddProperty("$MPElement[Name='Microsoft.SharePoint.2016.Group.SearchComponents']/Key$", $GroupFullName)
$InstComponentGroup.AddProperty("$MPElement[Name='Microsoft.SharePoint.2016.Group.SearchComponents']/System$", $Ssa.id.toString())
$InstComponentGroup.AddProperty("$MPElement[Name='Microsoft.SharePoint.2016.Group.SearchComponents']/ComponentType$", $GroupName)
$InstComponentGroup.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $GroupName)
$DiscoveryData.AddInstance($InstComponentGroup);
Handle-Errors(($global:EventLog_Fail_Create_Class -f "Group.SearchComponents"), $false);

$Rel3 = $DiscoveryData.CreateRelationshipInstance("$MPElement[Name='Microsoft.SharePoint.2016.Relationship.SearchServiceApplicationAndSearchComponentGroupMembership']$")
$Rel3.Source = $InstSystem
$Rel3.Target = $InstComponentGroup
$DiscoveryData.AddInstance($Rel3);
Handle-Errors(($global:EventLog_Fail_Create_Relationship -f "Relationship.SearchServiceApplicationAndSearchComponentGroupMembership"), $false);

$InstComponent = $DiscoveryData.CreateClassInstance($StrComponentClass)
$InstComponent.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $computerName)
$InstComponent.AddProperty("$MPElement[Name='Microsoft.SharePoint.2016.SearchComponent']/Id$", $SearchComponent.ComponentId.toString());
$SubSSA =$Ssa.Id.toString();
$InstComponent.AddProperty("$MPElement[Name='Microsoft.SharePoint.2016.SearchComponent']/System$", $SubSSA);
$strCompName = [regex]::Replace($SearchComponent.Name, "(Processing)|(Component)", "");
$InstComponent.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $strCompName);
$DiscoveryData.AddInstance($InstComponent);
Handle-Errors(($global:EventLog_Fail_Create_Class -f "SearchComponent "), $false);

$Rel4 = $DiscoveryData.CreateRelationshipInstance("$MPElement[Name='Microsoft.SharePoint.2016.Relationship.SearchComponentGroupMembership']$")
$Rel4.Source = $InstComponentGroup
$Rel4.Target = $InstComponent
$DiscoveryData.AddInstance($Rel4);
Handle-Errors(($global:EventLog_Fail_Create_Relationship -f "Relationship.SearchComponentGroupMembership"), $false);
}
}
}
}
}

}
Deliver-DiscoveryData($DiscoveryData);
</Script></Contents>
</File>
</Files>
</DataSource>
</MemberModules>
<Composition>
<Node ID="SearchDS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>