啟用 ACS 寫入動作

Microsoft.SystemCenter.EnableACSAction (WriteActionModuleType)

啟用 ACS 服務。

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
InputTypeSystem.BaseData

Member Modules:

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

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
CollectorServerstring$Config/CollectorServer$收集器伺服器

Source Code:

<WriteActionModuleType ID="Microsoft.SystemCenter.EnableACSAction" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element name="CollectorServer" type="xsd:string"/>
<xsd:element name="TargetComputerName" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="CollectorServer" Selector="$Config/CollectorServer$" ParameterType="string"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="EnableACS" TypeID="Windows!Microsoft.Windows.PowerShellWriteAction">
<ScriptName>EnableACSAction.ps1</ScriptName>
<ScriptBody><Script>
param($strCollectorServer, $strClientAgentGroup, $strTargetComputerName)

$message = "Agent Management Group: " + $strClientAgentGroup
Write-Host $message

$strACSKeyPath = "HKLM:SOFTWARE\Policies\Microsoft\AdtAgent\Parameters"
$strMOMKeyPath = "HKLM:SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Agent Management Groups\"+$strClientAgentGroup+"\Parent Health Services\0"
$strValueName = "LocalConfig"
set-itemproperty -path $strACSKeyPath -name $strValueName -value 1
$strValueName = "NoCache"
set-itemproperty -path $strACSKeyPath -name $strValueName -value 1

if (($strCollectorServer -eq "[Collector Server]") -or ($strCollectorServer -eq "") -or ($strCollectorServer -eq $null))
{

$Values = Get-ItemProperty -Path $strMOMKeyPath

if (($Values -eq $null) -or ($Values.NetworkName -eq $null))
{
$Value = $strTargetComputerName
}else{
$Value = $Values.NetworkName
}

$strValueName = "AdtServers"
Set-ItemProperty -path $strACSKeyPath -name $strValueName -value $Value
} else
{
$strValueName = "AdtServers"
$arrayCollectorServers = $strCollectorServer.Split(",")
for($item = 0; $item -lt $arrayCollectorServers.Length; $item++)
{
$arrayCollectorServers[$item] = $arrayCollectorServers[$item].trim()
}
Set-ItemProperty -path $strACSKeyPath -name $strValueName -value $arrayCollectorServers
}

$ServiceName = "AdtAgent"
Set-Service $ServiceName -StartupType "Automatic"
Write-Host "Service changed"

$stoppedCorrectly = $true
$adtService = Get-Service -Name $ServiceName
if($adtService.Status -eq "Running")
{
# we need to stop the service so it can pick up the registry changes

Write-Host "Stopping service so it can pick up changes"
Stop-Service $ServiceName
$adtService = Get-Service -Name $ServiceName
if ($adtService.Status -ne "Stopped")
{
Write-Host "Service not stopped"
$stoppedCorrectly = $false
}else
{
$Counter = 6

while ($Counter &gt; 0)
{
$Counter = $Counter - 1
$adtService = Get-Service -Name $ServiceName
if ($adtService.Status -eq "Stopped")
{
#
# 6 means Service Not Active
#

$stoppedCorrectly = $true
break
} else
{
$message = "InterrogateService return code:" + $adtService
Write-Host $message
}
$TimeOut = 10000
Start-Sleep -m $TimeOut
}

if ($stoppedCorrectly)
{
Write-Host "Service stopped correctly"
}else {
Write-Host "Unable to stop Service in 60 seconds"
Write-Host "You should manually stop and start the AdtAgent service on the target machine"
}
}
}

if($stoppedCorrectly)
{
Write-Host "Starting service"
$ServiceName = "AdtAgent"
Start-Service $ServiceName
$TimeOut = 10000
Start-Sleep -m $TimeOut
$adtService = Get-Service -Name $ServiceName
if ($adtService.Status -ne "Running")
{
Write-Host "Service was not started correctly"
Write-Host "start Service Manually"
} else {
Write-Host "Service started correctly"
}
}
</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>strCollectorServer</Name>
<Value>$Config/CollectorServer$</Value>
</Parameter>
<Parameter>
<Name>strClientAgentGroup</Name>
<Value>$Target/ManagementGroup/Name$</Value>
</Parameter>
<Parameter>
<Name>strTargetComputerName</Name>
<Value>$Config/TargetComputerName$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>90</TimeoutSeconds>
<StrictErrorHandling>true</StrictErrorHandling>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="EnableACS"/>
</Composition>
</Composite>
</ModuleImplementation>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>