<WriteActionModuleType ID="Microsoft.SQLServer.RunAs.2014.Addendum.SetHSServiceSidStateandRestart.WA" Accessibility="Public" Batching="false">
<Configuration/>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="ScriptWA" TypeID="Windows!Microsoft.Windows.ScriptWriteAction">
<ScriptName>SetHSServiceSidStateandRestart.vbs</ScriptName>
<Arguments/>
<ScriptBody><Script>
'==========================================================================
'
' NAME: SetHSServiceSidStateandRestart.vbs
'
' COMMENT: This is a write action script to set the HealthService to use a Service SID then bounce the agent
'
'==========================================================================
dim objWMIService, objProcess, strCommand
dim oShell, oShellEnv, strShell, computerName, oAPI
Set oShell = WScript.CreateObject("WScript.Shell")
Set oAPI = CreateObject("MOM.ScriptAPI")
'Log script event that we are starting task
Call oAPI.LogScriptEvent("SetHSServiceSidStateandRestart.vbs", 8675, 0, "Starting configuration of HealthService Service SID type then attempting restart of SCOM Health Service")
'configure the sidtype for HealthService
oShell.run "sc sidtype HealthService unrestricted"
'start the agent restart process
set oShellEnv = oShell.Environment("Process")
computerName = oShellEnv("ComputerName")
strCommand = "cmd /c net stop HealthService & 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)
WScript.echo "Sent restart command for SCOM Health Service on " & computerName </Script></ScriptBody>
<TimeoutSeconds>60</TimeoutSeconds>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="ScriptWA"/>
</Composition>
</Composite>
</ModuleImplementation>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>