Kaseya Community

Batch file to Kaseya script

  • We have this .bat file and want to make a K script, short of multiple executeshellscript lines is there a better way?

    Thanks

    IF EXIST C:\users\ (
    @echo off
    cd /D C:\Users
    REM ?-Clean Temp Folder?
    for /D %%a in (*.*) do DEL /F /S /Q "%%a\Appdata\Local\Temp\*.*"
    for /D %%a in (*.*) do FOR /D %%b IN ("%%a\Appdata\Local\Temp\*.*") DO RMDIR /S /Q "%%b"
    REM ?-Clean IE Cache?
    for /D %%a in (*.*) do DEL /F /S /Q "%%a\Appdata\Local\Microsoft\Windows\Temporary Internet Files\*.*"
    for /D %%a in (*.*) do FOR /D %%b IN ("%%a\Appdata\Local\Microsoft\Windows\Temporary Internet Files\*.*") DO RMDIR /S /Q "%%b"
    Rem ?-Clean Windows Temp?
    cd c:\windows\temp
     

    del %TEMP%\*.* /f /s /q
    )

    else (
    @echo off
    cd /D C:\Documents and Settings
    REM ?-Clean Temp Folder?
    for /D %%a in (*.*) do DEL /F /S /Q "%%a\Local Settings\Temp\*.*"
    for /D %%a in (*.*) do FOR /D %%b IN ("%%a\Local Settings\Temp\*.*") DO RMDIR /S /Q "%%b"
    REM ?-Clean IE Cache?
    for /D %%a in (*.*) do DEL /F /S /Q "%%a\Local Settings\Temporary Internet Files\*.*"
    for /D %%a in (*.*) do FOR /D %%b IN ("%%a\Local Settings\Temporary Internet Files\*.*") DO RMDIR /S /Q "%%b"

    Rem ?-Clean Windows Temp?
    cd c:\windows\temp
     

    del %TEMP%\*.* /f /s /q
    )

  • do it all in a single line with && .... I have made some absurdly long entries with that.

  • Figured out an alternative solution for you. Just write the .bat file to the agent machine's C:\ktemp than ran with an executeShellCommand as follows:

    writeFile ("example.bat", "C:\ktemp\example.bat", "All Windows Operating Systems", "Halt on Fail")

    executeShellCommand ("start C:\ktemp\example.bat", Execute as System", "All Windows Operating Systems", "Halt on Fail")

    You will just need to make sure you upload the .bat file to the KServer for this to work, when I tested this it worked like a charm.



    grammar
    [edited by: kmurphy at 1:21 PM (GMT -7) on Mar 20, 2014]
  • Kmurphy,

    Your suggestion is great and I've done the same on a lot of scripts, but to MSSINC's point, there should be a way to script this via Kaseya's scripting in agent procedures.