2017 02 22 11 23 29 services

Kaseya Agent Restart

Restart Kaseya Agent & Endpoint Services

Description

Recently found here (http://community.kaseya.com/xsp/f/26/t/22178.aspx) a need for a Kaseya Agent related services restart.

The procedure will call the Batch File...
The Batch File will:
- Stop the Kaseya Agent service and Kaseya Agent Endpoint Service
- Stop the Performance counters Service and the collection of Performance counters
- Restart the Performance counters Service and the collection of Performance counters
- Restart the Kaseya Agent service and Kaseya Agent Endpoint Service

Once complete, it will collect the resulting Log using a different procedure.

Developer
  • Name: Francis Germain
  • Company: Houston Technolology Group
  • Website: http://htg.co.nz
  • Contact Developer
  • Summary
  • Kaseya Agent Restart
  • 219 Downloads
  • Released on February 21st, 2017
  • Reviews

    Kaseya Agent Restart has no reviews.

    Discussion
    Gravatar for Francis Germain
    Francis Germain over 2 years ago

    Hi,

    I have discovered a BUG in the .BAT file...

    I have asked Kaseya Automation Support to update the package with a new version of the zip file.
    Once they have done it, the new zip file should be named "KaseyaAgentRestart 20170314.zip"

    In the meantime, please update your copy with the following change:.
    Copy/Paste everything between the ##BEGIN## and ##END## into RestartKaseyaAgent.bat

    ##BEGIN##
    @echo off
    REM ============================================================================
    REM
    REM NAME: RestartKaseyaAgent.bat
    REM AUTHOR: Francis Germain - SharePoint consultant - Houston Technology Group
    REM DATE: COMMENTS
    REM 18/02/2015 Initial creation + various changes
    REM 14/03/2017 Deleting the RestartAgent.log 1st and changed the redirections
    REM to append to it.
    REM Corrected the TASKKILL statement to kill AgentMon.exe (was
    REM killing KaseyaEndpoint.exe twice).
    REM
    REM No additional files required (ie. job files, etc.)
    REM ============================================================================

    REM Checking usage
    IF [%1]==[] GOTO USAGE
    IF [%2]==[] GOTO USAGE
    IF [%3]==[] GOTO USAGE

    REM Parameters
    :PARAMS
    SET WorkingDrive=%1
    SET WorkingDrive=%WorkingDrive:~0,2%

    SET WorkingDir=%2
    SET WorkingDir=%WorkingDir:"=%

    SET AgentID=%3
    SET AgentID=%AgentID:"=%
    SET AgentID=%AgentID:~-20%
    REM HSTTCH08761831408544

    GOTO MAIN

    REM Main program
    :MAIN
    %WorkingDrive%
    CD %WorkingDir%

    DEL %WorkingDir%\RestartAgent.log >NUL
    DEL %WorkingDir%\RestartAgentComplete.log >NUL

    REM This PING will allow the batch file to wait for 5 seconds (unless the Usage in incorrect)
    PING -n 5 127.0.0.1 >NUL

    REM ********** Stopping the HTG Agent
    ECHO Command: NET STOP KA%AgentID% >> %WorkingDir%\RestartAgent.log 2>>&1
    SC STOP KA%AgentID% >> %WorkingDir%\RestartAgent.log 2>>&1
    ECHO Command: NET STOP KAEND%AgentID% >> %WorkingDir%\RestartAgent.log 2>>&1
    SC STOP KAEND%AgentID% >> %WorkingDir%\RestartAgent.log 2>>&1

    REM This PING will allow the batch file to wait for 10 seconds (unless the Usage in incorrect)
    PING -n 10 127.0.0.1 >NUL

    REM Sometimes the Kaseya Agent takes ages to stop... a little bit of help is called for.
    ECHO Command: TASKKILL /F /IM AgentMon.exe >> %WorkingDir%\RestartAgent.log 2>>&1
    TASKKILL /F /IM AgentMon.exe.exe
    ECHO Command: TASKKILL /F /IM KaseyaEndpoint.exe >> %WorkingDir%\RestartAgent.log 2>>&1
    TASKKILL /F /IM KaseyaEndpoint.exe

    REM This PING will allow the batch file to wait for 5 seconds (unless the Usage in incorrect)
    PING -n 5 127.0.0.1 >NUL

    ECHO. >> %WorkingDir%\RestartAgent.log 2>>&1

    REM ********** Restarting HTG Agent Performance counters
    ECHO Searching Counters... >> %WorkingDir%\RestartAgent.log 2>>&1
    logman query | find "Counter" > C:\Temp\CounterList.txt
    FOR /F "tokens=1*" %%A IN (C:\Temp\CounterList.txt) DO (
    REM Searching File Location for Counter %%A
    logman query %%A | FIND "%WorkingDir%" > C:\Temp\CounterListDetailsTemp.txt
    FOR /F "tokens=1,2,3*" %%G IN (C:\Temp\CounterListDetailsTemp.txt) DO (
    IF [%%G]==[File:] (
    ECHO ****** %%A %%H >> %WorkingDir%\RestartAgent.log 2>>&1
    ECHO %%A %%H >> C:\Temp\CounterListDetails.txt
    )
    IF [%%G]==[Output] (
    ECHO ****** %%A %%I >> %WorkingDir%\RestartAgent.log 2>>&1
    ECHO %%A %%I >> C:\Temp\CounterListDetails.txt
    )
    )
    DEL C:\Temp\CounterListDetailsTemp.txt
    )

    ECHO. >> %WorkingDir%\RestartAgent.log 2>>&1
    ECHO Command: NET STOP SysmonLog >> %WorkingDir%\RestartAgent.log 2>>&1
    NET STOP SysmonLog >> %WorkingDir%\RestartAgent.log 2>>&1
    ECHO Command: NET STOP pla >> %WorkingDir%\RestartAgent.log 2>>&1
    NET STOP pla >> %WorkingDir%\RestartAgent.log 2>>&1

    REM This PING will allow the batch file to wait for 5 seconds (unless the Usage in incorrect)
    PING -n 5 127.0.0.1 >NUL

    ECHO. >> %WorkingDir%\RestartAgent.log 2>>&1
    ECHO Stopping the collection of performance counters >> %WorkingDir%\RestartAgent.log 2>>&1
    FOR /F "tokens=1,2,3,4,5,6* delims=\. " %%i IN (C:\Temp\CounterListDetails.txt) DO (
    ECHO Stopping %%i >> %WorkingDir%\RestartAgent.log 2>>&1
    logman stop %%i
    )

    REM This PING will allow the batch file to wait for 5 seconds (unless the Usage in incorrect)
    PING -n 5 127.0.0.1 >NUL

    ECHO. >> %WorkingDir%\RestartAgent.log 2>>&1
    ECHO Command: NET START SysmonLog >> %WorkingDir%\RestartAgent.log 2>>&1
    NET START SysmonLog >> %WorkingDir%\RestartAgent.log 2>>&1
    ECHO Command: NET START pla >> %WorkingDir%\RestartAgent.log 2>>&1
    NET START pla >> %WorkingDir%\RestartAgent.log 2>>&1


    PING -n 5 127.0.0.1 >NUL

    ECHO. >> %WorkingDir%\RestartAgent.log 2>>&1
    ECHO Starting the collection of performance counters >> %WorkingDir%\RestartAgent.log 2>>&1
    FOR /F "tokens=1,2,3,4,5,6* delims=\. " %%i IN (C:\Temp\CounterListDetails.txt) DO (
    ECHO Starting %%i >> %WorkingDir%\RestartAgent.log 2>>&1
    logman start %%i
    )

    DEL C:\Temp\CounterListDetails.txt
    DEL C:\Temp\CounterList.txt

    REM ********** Starting the HTG Agent
    ECHO. >> %WorkingDir%\RestartAgent.log 2>>&1
    ECHO Command: NET START KA%AgentID% >> %WorkingDir%\RestartAgent.log 2>>&1
    NET START KA%AgentID% >> %WorkingDir%\RestartAgent.log 2>>&1
    ECHO Command: NET START KAEND%AgentID% >> %WorkingDir%\RestartAgent.log 2>>&1
    NET START KAEND%AgentID% >> %WorkingDir%\RestartAgent.log 2>>&1

    REM This PING will allow the batch file to wait for 5 seconds (unless the Usage in incorrect)
    PING -n 5 127.0.0.1 >NUL

    ECHO. >> %WorkingDir%\RestartAgent.log 2>>&1
    DEL %WorkingDir%\RestartAgentLauncher.bat >> %WorkingDir%\RestartAgent.log 2>>&1
    ECHO DONE > %WorkingDir%\RestartAgentComplete.log

    GOTO END

    :USAGE
    ECHO ********** Incorrect parameters ******************************************************** >> %WorkingDir%\RestartAgent.log 2>>&1
    ECHO Usage: %0 WorkingDrive WorkingDir AgentID >> %WorkingDir%\RestartAgent.log 2>>&1
    ECHO ********** Incorrect parameters ******************************************************** >> %WorkingDir%\RestartAgent.log 2>>&1

    :END
    ##END##

    Gravatar for Francis Germain
    Francis Germain over 2 years ago

    Great: the comment stripped all new lines... that is going to be helpful !!!
    Just email me and I'll send you a copy of the new ZIP file.
    Francis Germain

    Gravatar for Francis Germain
    Francis Germain over 2 years ago

    Even better: here is a link to the file in my Dropbox...
    https://www.dropbox.com/s/vzu45xgev18womz/KaseyaAgentRestart%2020170314.zip?dl=0
    Francis Germain

    Gravatar for Francis Germain
    Francis Germain over 2 years ago

    I'll delete the file from my Dropbox one Kaseya Automation has updated the package.

    Gravatar for Levi Daily
    Levi Daily over 2 years ago

    Francis - We have this error on a few hundred machines since upgrading to 9.4. Is there a way run this script without having to put the Agent ID in the procedure? This could take some time.

    Gravatar for Francis Germain
    Francis Germain over 2 years ago

    Hi Levi... that is an excellent remark, and that made me realise there was another procedure (called "Cycle Kaseya Endpoint Service" writen by Gonzalo Carrillo) doing exactly what I believe you're after. I've now included an updated Agent Procedure in the "KaseyaAgentRestart 20170314.zip". I'll change the install description one the Automation Admin people have uploaded the new Zip file on the website. In the meantime, the download link from my Dropbox is somewhere in the comments above. Cheers.

    Gravatar for Francis Germain
    Francis Germain almost 2 years ago

    Downloadable Zip file was updated by the Kaseya Automation people (my thanks to them).
    I will leave the one from my Dropbox available for a few more weeks, then delete it.