Healthservice - RESTART

SCOM.Management.RestartHealthServiceHS.Task (Task)

Element properties:

TargetMicrosoft.SystemCenter.HealthService
AccessibilityPublic
CategoryCustom
EnabledTrue
RemotableFalse
Timeout120

Member Modules:

ID Module Type TypeId RunAs 
WA WriteAction Microsoft.Windows.ScriptWriteAction Default

Source Code:

<Task ID="SCOM.Management.RestartHealthServiceHS.Task" Accessibility="Public" Enabled="true" Target="SC!Microsoft.SystemCenter.HealthService" Timeout="120" Remotable="true">
<Category>Custom</Category>
<WriteAction ID="WA" TypeID="Windows!Microsoft.Windows.ScriptWriteAction">
<ScriptName>SCOM.Management.RestartHealthServiceHS.Task.vbs</ScriptName>
<Arguments/>
<ScriptBody><Script>
Option Explicit
On Error Resume Next
Dim ScriptName, oAPI, objWMIService, oShell, oShellEnv, computerName, strCommand, objProcess, objProgram, strShell

ScriptName = "SCOM.Management.RestartHealthServiceHS.Task.vbs"

'Load momscript API
Set oAPI = CreateObject("MOM.ScriptAPI")
'Log script event that we are starting
Call oAPI.LogScriptEvent(ScriptName, 1313, 2, "A command to restart the agent was sent. We will attempt to stop and then restart the Healthservice now.")

'Begin Healthservice Restart
Set oShell = WScript.CreateObject("WScript.Shell")
set oShellEnv = oShell.Environment("Process")
computerName = oShellEnv("ComputerName")
'Echo that we are about to start for task output
WScript.echo "Beginning Restart attempt for HealthService on " &amp; computerName
strCommand = "cmd /c net stop HealthService &amp; cmd /c net start HealthService"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set objProcess = objWMIService.Get("Win32_Process")
Set objProgram = objProcess.Methods_( _
"Create").InParameters.SpawnInstance_
objProgram.CommandLine = strCommand
Set strShell = objWMIService.ExecMethod( _
"Win32_Process", "Create", objProgram)
'Echo that we are restarting for task output
WScript.echo "Restarting HealthService on " &amp; computerName
'End Healthservice Restart
</Script></ScriptBody>
<TimeoutSeconds>60</TimeoutSeconds>
</WriteAction>
</Task>