A few agents are running older agent software or the windows 2003 operating system and as a result, they do connect always automatically to the core after a core service restart. Restarting the agent service on all these agents connects them back to the core. Additionally, a third party application that requires stopping the agent service but due to its nature but there is no feasable solution to restart the AppAssure Service once it finishes.
Disclaimer: This script is provided "as is" for the purpose of illustrating how AppAssure tasks may be performed in conjunction with PowerShell. AppAssure shall not be liable for any direct, indirect, incidental, consequential, or other damage alleged in connection with the furnishing or use of this script or of the principles it demonstrates.A few agents are running older agent software or the windows 2003 operating system and as a result, they do connect always automatically to the core after a core service restart. Restarting the agent service on all these agents connects them back to the core. Additionally, a third party application that requires stopping the agent service but due to its nature but there is no feasable solution to restart the AppAssure Service once it finishes.
How to restart the AppAssure Agent service on remote agents using Powershell?
A Powershell script to address the issue has been prepared. The script determines automatically which protected servers are unreachable by the core and stops (if necessary) and restarts the agent service using the host name of each agent (as opposed to the display name). Since the powershell commandlets have been implemented differently in for 5.3.x and 5.4.x builds, in an effort to make the script compatible with both, the relevant data is picked up straight from the Windows registry and filtered by the properties exposed via the native AppAssure commandlets.
The script is properly documented and the help can be accessed by running at an elevated command prompt:
get-help RestartAgents.4.ps1 -full
If necessary the script can be run periodically using the task scheduler.
The code is presented below between horizontal lines and attached to the KB.
________________________________________________________________________
.Synopsis
Restarts the appassureagent Service on remote Protected Servers
.Description
Gets the AppAssure Protected Servers that are unreachable from the current core and attempts connecting to them, inquiring the status of the AppAssure Service and restarts it.
.Parameter secs
default= 5 seconds
time interval between two queries of the service status
.Parameter repeats
default 12
number the queries before the operation times out
.Parameter $agentservice
default the appassureagent service
reserved for future use.
#>
param(
[int]$secs=5,
[int]$repeats=12.
[string]$agentservice="appassureagent"
)
cls
Write-host "Restart the AppAssure Agent Service on Remote Protected Servers"
Write-host "---------------------------------------------------------------`r`n"
#get current location (i.e. c:\temp)
$location = get-location
cd hklm:
cd \
#agent id-s
$agentpath = "hklm:\Software\AppRecovery\Core\Agents"
$IDPath = get-childitem -path $agentpath
$agenthash=@{}
for ($i=0;$i -lt $idpath.count;$i++){
$agentname=(Get-ItemProperty -path $IDPath[$i].Name -name displayname).displayname
$agenturi = (Get-ItemProperty -path $IDPath[$i].Name -name hosturi).hosturi
$agenthash.Add($agentname,($agenturi.replace("https://","").replace(":8006/apprecovery/api/agent/","")))
}
set-location $location
$counter = 0
$agentobj = @()
$agents = Get-ProtectedServers | where {"AuthenticationError","unreachable" -contains $_.status}
foreach($a in $agents.displayname){
if($agenthash.Containskey($a)){
$line = [pscustomobject]@{Name=$a;Host=$agenthash.get_item($a)}
$agentobj +=$line
}
}
if ($agents -ne $null){
Write-host "`r`nProtected Servers to Process"
$agentobj | format-table -AutoSize -Wrap
}
Else {Write-Host "`r`nAll Agents are reported as on line. Exiting..."; Exit}
foreach($agent in $agentobj){
#test connection
Write-Host "`r`nConnecting to $($agent.name) (host: $($agent.host))..."
$con = Test-Connection -ComputerName "$($agent.host)" -Count 1 -ErrorAction SilentlyContinue
if($con){
Write-Host "Connection to $($agent.name) successful"
#Check $agentserviceService status
$teststate = @(sc.exe "\\$($agent.host)" query $agentservice)
$teststate[3]
if($teststate[3] -like "*RUNNING*"){
$stopservice = @(sc.exe "@(sc.exe "\\$($agent.host)" query $agentservice)
$stopservice[3]
$counter=0
do{
start-sleep $secs
Write-Host "$(@(sc.exe "\\$($agent.host">\\$($agent.host)" query $agentservice)[3])"
$counter++
}while ((@(sc.exe "\\$($agent.host">\\$($agent.host)" query $agentservice)[3] -notlike "*STOPPED*") -and ($counter -le $repeats))
if ($counter -ge $repeats){Write-Host "Could not Stop the AppAssure Service on $($agent.name) in a timely manner"}
}
if($counter -le $repeats){
$counter=0
$startservice = @(sc.exe "\\$($agent.host)" start $agentservice)
$startservice[3]
$counter=0
do{
start-sleep $secs
Write-Host "$(@(sc.exe "\\$($agent.host)" query $agentservice)[3])"
$counter++
}while ((@(sc.exe "\\$($agent.host)" query $agentservice)[3] -notlike "*RUNNING*") -and ($counter -le $repeats))
if ($counter -ge $repeats){Write-Host "Could not Start the AppAssure Service on $($agent.name) in a timely manner"}
}
}
else {Write-Host "connection to $($agent.name) failed"
}
}
________________________________________________________________________
The codes
© ALL RIGHTS RESERVED. Feedback Terms of Use Privacy Cookie Preference Center