SCOMAgentHelper.WriteEvent.WA (WriteActionModuleType)

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
InputTypeSystem.BaseData
OutputTypeMicrosoft.Windows.SerializedObjectData
Commentfor agent Task

Member Modules:

ID Module Type TypeId RunAs 
POSH WriteAction Microsoft.Windows.PowerShellWriteAction Default

Overrideable Parameters:

IDParameterTypeSelector
EventIdstring$Config/EventId$
EventLogNamestring$Config/EventLogName$
Levelstring$Config/Level$
Messagestring$Config/Message$
Sourcestring$Config/Source$
WriteActionTimeoutSecondsint$Config/WriteActionTimeoutSeconds$

Source Code:

<WriteActionModuleType ID="SCOMAgentHelper.WriteEvent.WA" Accessibility="Public" Batching="false" Comment="for agent Task">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="EventId" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="EventLogName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="Level" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="Message" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="Source" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="WriteActionTimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="EventId" Selector="$Config/EventId$" ParameterType="string"/>
<OverrideableParameter ID="EventLogName" Selector="$Config/EventLogName$" ParameterType="string"/>
<OverrideableParameter ID="Level" Selector="$Config/Level$" ParameterType="string"/>
<OverrideableParameter ID="Message" Selector="$Config/Message$" ParameterType="string"/>
<OverrideableParameter ID="Source" Selector="$Config/Source$" ParameterType="string"/>
<OverrideableParameter ID="WriteActionTimeoutSeconds" Selector="$Config/WriteActionTimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="POSH" TypeID="Windows!Microsoft.Windows.PowerShellWriteAction">
<ScriptName>Write-MMStatusEvent.ps1</ScriptName>
<ScriptBody><Script>&lt;#
Write-MMStatusEvent.ps1
Author: Tyson Paul (https://monitoringguys.com/)
This is used by the SCOMAgentHelper.WriteEvent.WA which is called by the agent Task: SCOMAgentHelper.WriteMaintModeStatustoEventLog.Task

Version History
2020.08.05.1443 - Original

#&gt;

[CmdletBinding(DefaultParameterSetName='Parameter Set 1',
SupportsShouldProcess=$false,
PositionalBinding=$false,
HelpUri = 'http://www.microsoft.com/',
ConfirmImpact='Medium')]
[OutputType([Bool])]
Param(

# The event ID number
[Parameter(Mandatory=$true,
ValueFromPipeline=$false,
ValueFromPipelineByPropertyName=$false,
ValueFromRemainingArguments=$false,
Position=0,
ParameterSetName='Parameter Set 1')]
[ValidateNotNull()]
[ValidateNotNullOrEmpty()]
[Alias("Id")]
$EventId,

# Default: "Operations Manager"
$EventLogName = "Operations Manager",

# Valid values are: "info", "warn", "critical"
[ValidateSet("info", "warn", "critical")]
$Level = "info",

# This is a string value for the event parameters, separated by carets '^'. See examples.
[string]$Message,

# Default: "SCOMAgentHelper"
[string]$Source = "SCOMAgentHelper"
)


########################################################################################################
Function LogIt ([int]$EventID, [int]$Type = 2, [string]$Message = 'No message specified.', [bool]$Proceed = $false)
{
If ($Proceed )
{
$TimeStamp = (Get-Date -Format 'yyyy-MM-dd-HHmmss')
$output = @"

Message: $Message

ThisScriptInstanceGUID: $ThisScriptInstanceGUID
Whoami: $(whoami.exe)
TimeStamp: $TimeStamp

Any errors will appear below:

$($Error | Select-Object -Property *)

"@

$oEvent = New-Object -ComObject 'MOM.ScriptAPI'
$oEvent.LogScriptEvent("$ScriptName",$EventID,$Type,$output)
}
}
########################################################################################################

New-Alias -Name _LINE_ -Value Get-CurrentLineNumber -Description 'Returns the current line number in a PowerShell script file.' -ErrorAction SilentlyContinue
########################################################################################################

[int]$info = 0
[int]$Critical = 1
[int]$warning = 2
$api = New-Object -ComObject MOM.ScriptAPI
$ScriptName ='Write-MMStatusEvent.ps1'
$ThisScriptInstanceGUID = (New-Guid).Guid.Substring(((New-Guid).Guid.Length ) -6).ToUpper()


Try {
Import-Module SCOMAgentHelper -ErrorAction Stop -WarningAction SilentlyContinue
} Catch {
LogIt -EventID 9996 -Type $critical -Message "Line#: $(_LINE_):Unable to import module: [SCOMAgentHelper]. Exiting." -Proceed $true
Exit
}

$Message = "$($Message)^$($ThisScriptInstanceGUID)"
Try {
Write-SCOMEvent -EventId 3003 -Message $Message
"SUCCES WRITING TO LOG: $($Message)"
} Catch {
"FAILURE WRITING TO LOG: $($Message)"
}</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>EventId</Name>
<Value>$Config/EventId$</Value>
</Parameter>
<Parameter>
<Name>EventLogName</Name>
<Value>$Config/EventLogName$</Value>
</Parameter>
<Parameter>
<Name>Level</Name>
<Value>$Config/Level$</Value>
</Parameter>
<Parameter>
<Name>Message</Name>
<Value>$Config/Message$</Value>
</Parameter>
<Parameter>
<Name>Source</Name>
<Value>$Config/Source$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/WriteActionTimeoutSeconds$</TimeoutSeconds>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="POSH"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>Windows!Microsoft.Windows.SerializedObjectData</OutputType>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>