Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer_Discovery

Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer_Discovery (Discovery)

Discovery module for class Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer

Element properties:

TargetMicrosoft.Windows.Computer
EnabledTrue
Frequency14401
RemotableFalse

Object Discovery Details:

Discovered Classes and their attribuets:
  • Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer
    • ComputerName
    • AdminServiceStatus
    • IncomingMailServiceStatus
    • TimerServiceStatus
    • SearchServiceStatus
    • HelperSearchServiceStatus
    • SandboxCodeServiceStatus
    • TraceServiceStatus
    • AdminServiceInstanceStatus
    • IncomingMailServiceInstanceStatus
    • TimerServiceInstanceStatus
    • TraceServiceInstanceStatus
    • HelperSearchServiceInstanceStatus
    • SearchServiceInstanceStatus
    • SandCodeServiceInstanceStatus
    • SPRole
    • FarmID
    • ComputerID
    • PrincipalName
    • SPVersion
    • SPMajorVersion

Member Modules:

ID Module Type TypeId RunAs 
Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer_Discovery DataSource Microsoft.Windows.TimedPowerShell.DiscoveryProvider Microsoft.SharePoint.Foundation.2010.AdminAccount

Source Code:

<Discovery ID="Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer_Discovery" Enabled="true" Target="Windows!Microsoft.Windows.Computer" ConfirmDelivery="true" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer">
<Property TypeID="MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer" PropertyID="ComputerName"/>
<Property TypeID="MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer" PropertyID="AdminServiceStatus"/>
<Property TypeID="MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer" PropertyID="IncomingMailServiceStatus"/>
<Property TypeID="MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer" PropertyID="TimerServiceStatus"/>
<Property TypeID="MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer" PropertyID="SearchServiceStatus"/>
<Property TypeID="MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer" PropertyID="HelperSearchServiceStatus"/>
<Property TypeID="MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer" PropertyID="SandboxCodeServiceStatus"/>
<Property TypeID="MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer" PropertyID="TraceServiceStatus"/>
<Property TypeID="MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer" PropertyID="AdminServiceInstanceStatus"/>
<Property TypeID="MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer" PropertyID="IncomingMailServiceInstanceStatus"/>
<Property TypeID="MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer" PropertyID="TimerServiceInstanceStatus"/>
<Property TypeID="MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer" PropertyID="TraceServiceInstanceStatus"/>
<Property TypeID="MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer" PropertyID="HelperSearchServiceInstanceStatus"/>
<Property TypeID="MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer" PropertyID="SearchServiceInstanceStatus"/>
<Property TypeID="MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer" PropertyID="SandCodeServiceInstanceStatus"/>
<Property TypeID="MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer" PropertyID="SPRole"/>
<Property TypeID="MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer" PropertyID="FarmID"/>
<Property TypeID="MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer" PropertyID="ComputerID"/>
<Property TypeID="MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer" PropertyID="PrincipalName"/>
<Property TypeID="MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer" PropertyID="SPVersion"/>
<Property TypeID="MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer" PropertyID="SPMajorVersion"/>
</DiscoveryClass>
</DiscoveryTypes>
<DataSource ID="Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer_Discovery" RunAs="SharePoint!Microsoft.SharePoint.Foundation.2010.AdminAccount" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
<IntervalSeconds>14401</IntervalSeconds>
<SyncTime/>
<ScriptName>SPServerExtension.ps1</ScriptName>
<ScriptBody><Script>

param($SourceId,$ManagedEntityId)

$ErrorActionPreference = "Stop"


function _AdvisorGetTypedValue()
{
param([string] $type, [string] $v)
if (($type -eq "String") -or ($v -eq $null) )
{
return $v
}
if ($v.Trim().Length -gt 0)
{
switch ($type)
{
"Boolean" { if ($v -eq "true") {$true} else {$false} }
"DateTime" { [System.DateTime]::Parse($v) }
"Guid" { New-Object System.Guid($v) }
"Integer" { [int]$v }
"Float" { [float]$v }
}
}
else
{
$null
}
}
function _AdvisorAddProperty()
{
param([object]$o, [string]$p, [object]$v, [bool]$key)
if (($key -eq $true) -and ($v -eq $null))
{
Throw "Key property [$p] cannot be null."
}
if ($v -ne $null)
{
$o.AddProperty($p, $v)
}
}
function _AdvisorCreateBaseObject([string] $className, [string] $displayName)
{
$o = new-object PSObject
$o | Add-Member -MemberType NoteProperty -Name "ClassName" -Value $className
$o | Add-Member -MemberType NoteProperty -Name "DisplayName" -Value $displayName
$o | Add-Member -MemberType NoteProperty -Name "ParentClass" -Value $null
return $o
}


$scriptargs = new-object psobject
$scriptargs | add-member NoteProperty "SourceId" $SourceId
$scriptargs | add-member NoteProperty "ManagedEntityId" $ManagedEntityId


if (!$global:AdvisorEmulateRuntime)
{
$oAPI = new-object -comObject "MOM.ScriptAPI"
}


$discovery = New-Object PSObject
$discovery | Add-Member -MemberType NoteProperty -Name "_logFile" -Value $null
$discovery | Add-Member -MemberType NoteProperty -Name "_scomAPI" -Value $oAPI
$discovery | Add-Member -MemberType NoteProperty -Name "_discoveryData" -Value $null
$discovery | Add-Member -MemberType NoteProperty -Name "ParentClass" -Value $null
$discovery | Add-Member -MemberType NoteProperty -Name "Classes" -Value @()
$discovery | Add-Member -MemberType ScriptMethod -Name "AddInstance" -Value {
$o = $args[0]
$this.WriteDiscoveryDebugLog( "-Instance Added-", $o )
$this.Classes += $o
}
$discovery | Add-Member -MemberType ScriptMethod -Name "WriteEventLog" -Value {
$text = $args[0]
$eventId = $args[1]
$sev = $args[2]
if (($sev -eq $null) -or ($sev -gt 4)) { $sev = 0 }
if (($eventId -eq $null) -or ($eventId -lt 0) -or ($eventId -gt 20000)) { $eventId = 19000 }
if ($global:AdvisorEmulateRuntime)
{
Write-Debug "[Advisor Script(EventLog): Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer] ""$text"" $sev $eventId"
}
else
{
$this._scomAPI.LogScriptEvent("Advisor Script: Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer", $eventId, $sev, $text)
}
}
$discovery | Add-Member -MemberType ScriptMethod -Name "WriteDiscoveryDebugLog" -Value {
$u = [Environment]::UserDomainName + "\" + [Environment]::UserName
$date = Get-Date
$header = "$date`tMicrosoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer`t$u"
if (($args -ne $null) -and ($args.Count -gt 0) -and ($args[0] -is [string]))
{
$header += "`t" + $args[0]
$args = @($args | Select-Object -Last ($args.Count-1))
}
$output = @($header, $args)
$output | Out-String -Width 256 | Write-Debug
if ($this._logFile -ne $null)
{
$output | Out-String | Add-Content -Path $this._logFile
}
}
$discovery | Add-Member -MemberType ScriptMethod -Name "CreateClassInstance" -Value {
return AdvisorCreateClassInstance "Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer"
}

$discoveryDebugFilePath = Join-Path $Env:ProgramFiles "\System Center Advisor\discovery.txt"
if (Test-Path $discoveryDebugFilePath)
{
$discovery._logFile = $discoveryDebugFilePath
}
del variable:\discoveryDebugFilePath -force &#x2013;ErrorAction SilentlyContinue

$discovery | Add-Member -MemberType ScriptMethod -Name "CreateDiscoveryData" -Value {
if ($global:AdvisorEmulateRuntime)
{
$i = 0
foreach ($o in $this.Classes)
{
$i = $i + 1
$this.WriteDiscoveryDebugLog("Discovered Class $i", $o )
}
}
else
{
$this._discoveryData = $this._scomAPI.CreateDiscoveryData(0, $scriptargs.SourceId, $scriptargs.ManagedEntityId)
foreach ($o in $this.Classes)
{
$instance = $null
switch ($o.ClassName)
{
"Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer"
{
$instance = $this._discoveryData.CreateClassInstance("$MPElement[Name='MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer']$")

_AdvisorAddProperty $instance "$MPElement[Name='MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer']/ComputerName$" $o.ComputerName $false
_AdvisorAddProperty $instance "$MPElement[Name='MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer']/AdminServiceStatus$" $o.AdminServiceStatus $false
_AdvisorAddProperty $instance "$MPElement[Name='MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer']/IncomingMailServiceStatus$" $o.IncomingMailServiceStatus $false
_AdvisorAddProperty $instance "$MPElement[Name='MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer']/TimerServiceStatus$" $o.TimerServiceStatus $false
_AdvisorAddProperty $instance "$MPElement[Name='MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer']/SearchServiceStatus$" $o.SearchServiceStatus $false
_AdvisorAddProperty $instance "$MPElement[Name='MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer']/HelperSearchServiceStatus$" $o.HelperSearchServiceStatus $false
_AdvisorAddProperty $instance "$MPElement[Name='MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer']/SandboxCodeServiceStatus$" $o.SandboxCodeServiceStatus $false
_AdvisorAddProperty $instance "$MPElement[Name='MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer']/TraceServiceStatus$" $o.TraceServiceStatus $false
_AdvisorAddProperty $instance "$MPElement[Name='MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer']/AdminServiceInstanceStatus$" $o.AdminServiceInstanceStatus $false
_AdvisorAddProperty $instance "$MPElement[Name='MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer']/IncomingMailServiceInstanceStatus$" $o.IncomingMailServiceInstanceStatus $false
_AdvisorAddProperty $instance "$MPElement[Name='MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer']/TimerServiceInstanceStatus$" $o.TimerServiceInstanceStatus $false
_AdvisorAddProperty $instance "$MPElement[Name='MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer']/TraceServiceInstanceStatus$" $o.TraceServiceInstanceStatus $false
_AdvisorAddProperty $instance "$MPElement[Name='MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer']/HelperSearchServiceInstanceStatus$" $o.HelperSearchServiceInstanceStatus $false
_AdvisorAddProperty $instance "$MPElement[Name='MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer']/SearchServiceInstanceStatus$" $o.SearchServiceInstanceStatus $false
_AdvisorAddProperty $instance "$MPElement[Name='MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer']/SandCodeServiceInstanceStatus$" $o.SandCodeServiceInstanceStatus $false
_AdvisorAddProperty $instance "$MPElement[Name='MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer']/SPRole$" $o.SPRole $false
_AdvisorAddProperty $instance "$MPElement[Name='MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer']/FarmID$" $o.FarmID $false
_AdvisorAddProperty $instance "$MPElement[Name='MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer']/ComputerID$" $o.ComputerID $false
_AdvisorAddProperty $instance "$MPElement[Name='MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer']/PrincipalName$" $o.PrincipalName $false
_AdvisorAddProperty $instance "$MPElement[Name='MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer']/SPVersion$" $o.SPVersion $false
_AdvisorAddProperty $instance "$MPElement[Name='MicrosoftKnowledgeServicesSharePointFoundation2010Library!Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer']/SPMajorVersion$" $o.SPMajorVersion $false
_AdvisorAddProperty $instance "$MPElement[Name='System!System.Entity']/DisplayName$" $o.DisplayName $false
_AdvisorAddProperty $instance "$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$" $this.ParentClass.PrincipalName $true


}
default {Throw "Unsupported ClassName: " + $o.ClassName}
}
$this._discoveryData.AddInstance($instance)
}
return $this._discoveryData
}
}

function AdvisorCreateClassInstance([string] $className)
{
$o = $null
switch ($className)
{
"Microsoft.KnowledgeServices.SharePoint.Foundation.2010.SPServer"
{
$o = New-Object PSObject
$o | Add-Member -MemberType NoteProperty -Name ClassName -Value $className
$o | Add-Member -MemberType NoteProperty -Name DisplayName -Value "SharePoint Server"

$o | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value $null -Force
$o | Add-Member -MemberType NoteProperty -Name "AdminServiceStatus" -Value $null -Force
$o | Add-Member -MemberType NoteProperty -Name "IncomingMailServiceStatus" -Value $null -Force
$o | Add-Member -MemberType NoteProperty -Name "TimerServiceStatus" -Value $null -Force
$o | Add-Member -MemberType NoteProperty -Name "SearchServiceStatus" -Value $null -Force
$o | Add-Member -MemberType NoteProperty -Name "HelperSearchServiceStatus" -Value $null -Force
$o | Add-Member -MemberType NoteProperty -Name "SandboxCodeServiceStatus" -Value $null -Force
$o | Add-Member -MemberType NoteProperty -Name "TraceServiceStatus" -Value $null -Force
$o | Add-Member -MemberType NoteProperty -Name "AdminServiceInstanceStatus" -Value $null -Force
$o | Add-Member -MemberType NoteProperty -Name "IncomingMailServiceInstanceStatus" -Value $null -Force
$o | Add-Member -MemberType NoteProperty -Name "TimerServiceInstanceStatus" -Value $null -Force
$o | Add-Member -MemberType NoteProperty -Name "TraceServiceInstanceStatus" -Value $null -Force
$o | Add-Member -MemberType NoteProperty -Name "HelperSearchServiceInstanceStatus" -Value $null -Force
$o | Add-Member -MemberType NoteProperty -Name "SearchServiceInstanceStatus" -Value $null -Force
$o | Add-Member -MemberType NoteProperty -Name "SandCodeServiceInstanceStatus" -Value $null -Force
$o | Add-Member -MemberType NoteProperty -Name "SPRole" -Value $null -Force
$o | Add-Member -MemberType NoteProperty -Name "FarmID" -Value $null -Force
$o | Add-Member -MemberType NoteProperty -Name "ComputerID" -Value $null -Force
$o | Add-Member -MemberType NoteProperty -Name "PrincipalName" -Value $null -Force
$o | Add-Member -MemberType NoteProperty -Name "SPVersion" -Value $null -Force
$o | Add-Member -MemberType NoteProperty -Name "SPMajorVersion" -Value $null -Force


}
default {Throw "Unsupported ClassName: " + $className}
}
return $o
}



$current = _AdvisorCreateBaseObject "Microsoft.Windows.Computer" ""
$current | Add-Member -MemberType NoteProperty -Name "PrincipalName" -Value "$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$" -Force
$current | Add-Member -MemberType NoteProperty -Name "DNSName" -Value "$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/DNSName$" -Force
$current | Add-Member -MemberType NoteProperty -Name "NetbiosComputerName" -Value "$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/NetbiosComputerName$" -Force
$current | Add-Member -MemberType NoteProperty -Name "NetbiosDomainName" -Value "$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/NetbiosDomainName$" -Force
$current | Add-Member -MemberType NoteProperty -Name "IPAddress" -Value "$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/IPAddress$" -Force
$current | Add-Member -MemberType NoteProperty -Name "NetworkName" -Value "$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/NetworkName$" -Force
$current | Add-Member -MemberType NoteProperty -Name "ActiveDirectoryObjectSid" -Value "$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/ActiveDirectoryObjectSid$" -Force
$current | Add-Member -MemberType NoteProperty -Name "IsVirtualMachine" -Value $null -Force;$current.IsVirtualMachine = _AdvisorGetTypedValue "Boolean" "$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/IsVirtualMachine$"
$current | Add-Member -MemberType NoteProperty -Name "DomainDnsName" -Value "$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/DomainDnsName$" -Force
$current | Add-Member -MemberType NoteProperty -Name "OrganizationalUnit" -Value "$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/OrganizationalUnit$" -Force
$current | Add-Member -MemberType NoteProperty -Name "ForestDnsName" -Value "$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/ForestDnsName$" -Force
$current | Add-Member -MemberType NoteProperty -Name "ActiveDirectorySite" -Value "$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/ActiveDirectorySite$" -Force
$current | Add-Member -MemberType NoteProperty -Name "LogicalProcessors" -Value $null -Force;$current.LogicalProcessors = _AdvisorGetTypedValue "Integer" "$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/LogicalProcessors$"
$current | Add-Member -MemberType NoteProperty -Name "DisplayName" -Value "$Target/Property[Type="System!System.Entity"]/DisplayName$" -Force

$discovery.ParentClass = $current


[ScriptBlock]$mainScriptBlock = {
PARAM($InvokeParameter)




function Handle-Errors([string]$ErrMsg)
{
if (! $error)
{
return;
}
$ErrorString = $ErrMsg;

$EventLog_Format = "`nCurrent PID: {0}`nInvocationInfo.MyCommand: {1}`nInvocationInfo.ScriptLineNumber: {2}`nInvocationInfo.OffsetInLine: {3}`nInvocationInfo.ScriptName: {4}`nInvocationInfo.Line: {5}`nInvocationInfo.PositionMessage: {6}`nInvocationInfo.InvocationName: {7}`nInvocationInfo.PipelineLength: {8}`nInvocationInfo.PipelinePosition: {9}`n";

$EventLog_Template = "[{0} in Advisor script] {1} {2}";
$Exception = $error[$error.Count - 1];
if ($Exception.InvocationInfo -ne $null)
{
$ErrorString += ($EventLog_Format -f $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;
}

$EventObject = New-Object Diagnostics.EventLog;
$EventObject.Source = "Operations Manager"
$EventObject.WriteEntry(($EventLog_Template -f $InnerException.GetType().FullName, $ErrorString, $Exception.Message), [System.Diagnostics.EventLogEntryType]::Error, 8000);
$error.Clear();
}

Function Get-SharepointInstallation
{
$registryKey2010 = "HKLM:\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0"
$registryKey2013 = "HKLM:\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\15.0"
if ((Test-Path -Path $registryKey2010) -or (Test-Path -Path $registryKey2013))
{
if ((Get-ItemProperty -Path $registryKey2010 -ErrorAction SilentlyContinue).Sharepoint -eq "Installed" -or `
(Get-ItemProperty -Path $registryKey2013 -ErrorAction SilentlyContinue).Sharepoint -eq "Installed")
{
return $true
}
}
return $false
}

Function IsSharePointEnvironmentPrepared
{
$isPrepared = $true


try
{

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | Out-Null


$webAdmin = Join-Path $env:windir -ChildPath "\system32\inetsrv\Microsoft.Web.Administration.dll"
[System.Reflection.Assembly]::LoadFrom($webAdmin) | Out-Null

}
catch
{
$isPrepared = $false
}

if ($null -eq [Microsoft.SharePoint.Administration.SPServer]::Local)
{
$isPrepared = $false
}
$error.Clear()
return $isPrepared
}

function Get-HelpSearchInstanceID()
{
$HelpSearchID = "";

$AdminWeb = [Microsoft.SharePoint.Administration.SPAdministrationWebApplication]::Local;
if ($AdminWeb -ne $null)
{
foreach ($ContentDB in $AdminWeb.ContentDatabases)
{
$HelpSearchInstance = $ContentDB.SearchServiceInstance;
if ($null -ne $HelpSearchInstance)
{
$HelpSearchID = $HelpSearchInstance.Id.ToString();
}
}
}

return $HelpSearchID;
}

function Get-ServiceStatus([string]$ServiceName){
$status = ""
try{
$service = Get-Service $ServiceName -ErrorAction SilentlyContinue

if ( ! $service )
{
$status = "Missing"
}
else
{
$status = $service.Status.ToString()
}
}catch{
$Error.Clear()
}
return $status
}




function ServerDiscovery()
{
$global:advisorDiscoveredObjects = New-Object psobject
$global:advisorDiscoveredObjects | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value ""
$global:advisorDiscoveredObjects | Add-Member -MemberType NoteProperty -Name "AdminServiceStatus" -Value ""
$global:advisorDiscoveredObjects | Add-Member -MemberType NoteProperty -Name "IncomingMailServiceStatus" -Value ""
$global:advisorDiscoveredObjects | Add-Member -MemberType NoteProperty -Name "TimerServiceStatus" -Value ""
$global:advisorDiscoveredObjects | Add-Member -MemberType NoteProperty -Name "SearchServiceStatus" -Value ""
$global:advisorDiscoveredObjects | Add-Member -MemberType NoteProperty -Name "HelperSearchServiceStatus" -Value ""
$global:advisorDiscoveredObjects | Add-Member -MemberType NoteProperty -Name "SandboxCodeServiceStatus" -Value ""
$global:advisorDiscoveredObjects | Add-Member -MemberType NoteProperty -Name "TraceServiceStatus" -Value ""
$global:advisorDiscoveredObjects | Add-Member -MemberType NoteProperty -Name "AdminServiceInstanceStatus" -Value ""
$global:advisorDiscoveredObjects | Add-Member -MemberType NoteProperty -Name "IncomingMailServiceInstanceStatus" -Value ""
$global:advisorDiscoveredObjects | Add-Member -MemberType NoteProperty -Name "TimerServiceInstanceStatus" -Value ""
$global:advisorDiscoveredObjects | Add-Member -MemberType NoteProperty -Name "TraceServiceInstanceStatus" -Value ""
$global:advisorDiscoveredObjects | Add-Member -MemberType NoteProperty -Name "HelperSearchServiceInstanceStatus" -Value ""
$global:advisorDiscoveredObjects | Add-Member -MemberType NoteProperty -Name "SearchServiceInstanceStatus" -Value ""
$global:advisorDiscoveredObjects | Add-Member -MemberType NoteProperty -Name "SandCodeServiceInstanceStatus" -Value ""
$global:advisorDiscoveredObjects | Add-Member -MemberType NoteProperty -Name "SPRole" -Value ""
$global:advisorDiscoveredObjects | Add-Member -MemberType NoteProperty -Name "FarmID" -Value ""
$global:advisorDiscoveredObjects | Add-Member -MemberType NoteProperty -Name "ComputerID" -Value ""
$global:advisorDiscoveredObjects | Add-Member -MemberType NoteProperty -Name "PrincipalName" -Value ""
$global:advisorDiscoveredObjects | Add-Member -MemberType NoteProperty -Name "SPVersion" -Value ""
$global:advisorDiscoveredObjects | Add-Member -MemberType NoteProperty -Name "SPMajorVersion" -Value 0


Try
{
if ((IsSharePointEnvironmentPrepared) -eq $true)
{
$SPAdmin = "Microsoft.SharePoint.Administration.SPAdministrationService";
$SPSearch = "Microsoft.SharePoint.Search.Administration.SPSearchService";
$SPIncomingMail = "Microsoft.SharePoint.Administration.SPIncomingEmailService";
$SPTimer = "Microsoft.SharePoint.Administration.SPTimerService";
$SPUserCode = "Microsoft.SharePoint.Administration.SPUserCodeService";
$SPTracing = "Microsoft.SharePoint.Administration.SPTracingService";


$global:advisorDiscoveredObjects.ComputerName = [System.Net.Dns]::GetHostName()
$global:advisorDiscoveredObjects.AdminServiceStatus = Get-ServiceStatus "SPAdminV4"
$global:advisorDiscoveredObjects.IncomingMailServiceStatus = Get-ServiceStatus "SMTPSVC"
$global:advisorDiscoveredObjects.TimerServiceStatus = Get-ServiceStatus "SPTimerV4"
$global:advisorDiscoveredObjects.SearchServiceStatus = Get-ServiceStatus "OSearch14"
$global:advisorDiscoveredObjects.HelperSearchServiceStatus = Get-ServiceStatus "SPSearch4"
$global:advisorDiscoveredObjects.SandboxCodeServiceStatus = Get-ServiceStatus "SPUserCodeV4"
$global:advisorDiscoveredObjects.TraceServiceStatus = Get-ServiceStatus "SPTraceV4"


$HelpSearchID = Get-HelpSearchInstanceID;
$LocalServer = [Microsoft.SharePoint.Administration.SPServer]::Local;
$global:advisorDiscoveredObjects.SPRole = $LocalServer.Role.ToString()
$global:advisorDiscoveredObjects.FarmID = $LocalServer.Farm.Id.ToString()
$global:advisorDiscoveredObjects.ComputerID = "$invokeParameter"
$global:advisorDiscoveredObjects.PrincipalName = "$invokeParameter"
$SrvInstances = $LocalServer.ServiceInstances

$SPFarm = [Microsoft.SharePoint.Administration.SPFarm]::Local
if ($SPFarm -ne $null)
{
$global:advisorDiscoveredObjects.SPVersion = $SPFarm.BuildVersion.ToString()
$global:advisorDiscoveredObjects.SPMajorVersion = $SPFarm.BuildVersion.Major
}
foreach($SrvInstance in $SrvInstances)
{
$typeName = $SrvInstance.Service.GetType().FullName
switch ($typeName)
{
$SPAdmin
{
$global:advisorDiscoveredObjects.AdminServiceInstanceStatus = $SrvInstance.Status.ToString()
}
$SPIncomingMail
{
$global:advisorDiscoveredObjects.IncomingMailServiceInstanceStatus = $SrvInstance.Status.ToString()
}
$SPTimer
{
$global:advisorDiscoveredObjects.TimerServiceInstanceStatus = $SrvInstance.Status.ToString()
}
$SPTracing
{
$global:advisorDiscoveredObjects.TraceServiceInstanceStatus = $SrvInstance.Status.ToString()
}
$SPSearch
{

if ($HelpSearchID -eq $SrvInstance.Id.ToString())
{
$global:advisorDiscoveredObjects.HelperSearchServiceInstanceStatus = $SrvInstance.Status.ToString()
}
elseif ("SPSearchServiceInstance" -eq $SrvInstance.GetType().Name)
{
$global:advisorDiscoveredObjects.SearchServiceInstanceStatus = $SrvInstance.Status.ToString()
}
}
$SPUserCode
{
$global:advisorDiscoveredObjects.SandCodeServiceInstanceStatus = $SrvInstance.Status.ToString()
}
}

}
}
}
Catch
{
Handle-Errors "SPServerExtension"
}
}

if (Get-SharePointInstallation -eq $true)
{
ServerDiscovery
}

}

Function Test-NeedPSRemoting
{
$script:SharePointPSVer = 0
$registryKey2010 = "HKLM:\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0"
$registryKey2013 = "HKLM:\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\15.0"

if (Test-Path -Path $registryKey2010)
{
if ((Get-ItemProperty -Path $registryKey2010 -ErrorAction SilentlyContinue).Sharepoint -eq "Installed")
{
$script:SharePointPSVer = 2010
}
}
if (Test-Path -Path $registryKey2013)
{
if ((Get-ItemProperty -Path $registryKey2013 -ErrorAction SilentlyContinue).Sharepoint -eq "Installed")
{
$script:SharePointPSVer = 2013
}
}

$PSCLRVersion = [System.String]::Format("{0}.{1}", $PSVersionTable.CLRVersion.Major, $PSVersionTable.CLRVersion.Minor)
if (($PSCLRVersion -ieq "2.0") -and ($script:SharePointPSVer -ieq 2013))
{
return $true
}
return $false
}

if ((Test-NeedPSRemoting))
{
[bool]$script:psRemotingEnabled = $false

$winRMService = (Get-Service WinRM -ErrorAction SilentlyContinue)
if ($winRMService -ne $null)
{
if ($winRMService.Status -ieq [System.ServiceProcess.ServiceControllerStatus]::Stopped)
{
$winRMService.Start()
$winRMService.WaitForStatus([System.ServiceProcess.ServiceControllerStatus]::Running, [System.TimeSpan]::FromSeconds(15))
}
$psSessionConfiguration = (Get-PSSessionConfiguration -Name "Microsoft.PowerShell" -ErrorAction SilentlyContinue)
if ($psSessionConfiguration.Permission.Contains("BUILTIN\Administrators AccessAllowed"))
{
winrm quickconfig -quiet
$script:psRemotingEnabled = $true
}
else
{
Enable-PSRemoting -Force
winrm quickconfig -quiet
$script:psRemotingEnabled = $true
Set-Item WSMan:\localhost\Shell\MaxShellsPerUser 50
}
}


if ($script:psRemotingEnabled -eq $true)
{
$session = New-PSSession
Invoke-Command -Session $session -ScriptBlock $mainScriptBlock -ArgumentList @($discovery.ParentClass.PrincipalName)
$global:advisorDiscoveredObjects = Invoke-Command -Session $session -ScriptBlock {$global:advisorDiscoveredObjects}
Remove-PSSession -Session $session
}
}
else
{
&amp; $mainScriptBlock $discovery.ParentClass.PrincipalName
}

Function AddDiscoveryInstance($discoveredObjects)
{
foreach($item in $discoveredObjects)
{
$serverInst = $discovery.CreateClassInstance()
$serverInst.ComputerName = $item.ComputerName
$serverInst.AdminServiceStatus = $item.AdminServiceStatus
$serverInst.IncomingMailServiceStatus = $item.IncomingMailServiceStatus
$serverInst.TimerServiceStatus = $item.TimerServiceStatus
$serverInst.SearchServiceStatus = $item.SearchServiceStatus
$serverInst.HelperSearchServiceStatus = $item.HelperSearchServiceStatus
$serverInst.SandboxCodeServiceStatus = $item.SandboxCodeServiceStatus
$serverInst.TraceServiceStatus = $item.TraceServiceStatus
$serverInst.AdminServiceInstanceStatus = $item.AdminServiceInstanceStatus
$serverInst.IncomingMailServiceInstanceStatus = $item.IncomingMailServiceInstanceStatus
$serverInst.TimerServiceInstanceStatus = $item.TimerServiceInstanceStatus
$serverInst.TraceServiceInstanceStatus = $item.TraceServiceInstanceStatus
$serverInst.HelperSearchServiceInstanceStatus = $item.HelperSearchServiceInstanceStatus
$serverInst.SearchServiceInstanceStatus = $item.SearchServiceInstanceStatus
$serverInst.SandCodeServiceInstanceStatus = $item.SandCodeServiceInstanceStatus
$serverInst.SPRole = $item.SPRole
$serverInst.FarmID = $item.FarmID
$serverInst.ComputerID = $item.ComputerID
$serverInst.PrincipalName = $item.PrincipalName
$serverInst.SPVersion = $item.SPVersion
$serverInst.SPMajorVersion = $item.SPMajorVersion
$discovery.AddInstance( $serverInst )
}
}

if ($global:advisorDiscoveredObjects -ne $null)
{
AddDiscoveryInstance $global:advisorDiscoveredObjects
}

$discoverydata = $discovery.CreateDiscoveryData()
$discoverydata

</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>SourceId</Name>
<Value>$MPElement$</Value>
</Parameter>
<Parameter>
<Name>ManagedEntityId</Name>
<Value>$Target/Id$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>300</TimeoutSeconds>
<StrictErrorHandling>false</StrictErrorHandling>
</DataSource>
</Discovery>