How To : Deploy Kaspersky Endpoint Security Cloud with PowerShell

Configuration

Intro

I had to deploy Kaspersky Endpoint Security Cloud to replace a standard Kaspersky Enpoint Security architecture. To do so I used psexec tool and a PowerShell script.

Network share

We need a network share (accessible by all) where we will put KESC.exe and a batch script (deploy.bat) in.

Batch script

Intro

The batch script will record up to two registry keys. It will allow to run KESC.exe -s up to twice in order to : first uninstall Kasperky Network Agent and then install Kaspersky Endpoint Security Cloud. (source : https://support.kaspersky.com/13693).

Code

ECHO ON

REM if exist c:\uninstall (
REM	GOTO INSTALL
REM ) else (
REM	echo > c:\uninstall
REM	\\SRV-DATA\share\KLSHARE\Packages\KES\exec\setup.exe /x
REM	GOTO END
REM )

set SHARE_PATH=\\SRV-DATA\share
set PACKAGE_NAME=KESC.exe
set __KESCLOUD_ROOT_KEY="HKLM\Software\KasperskyLab\KESCloud"
set __KESCLOUD_KEY_NAME="AutoPackageInstalled"
set __KESCLOUD_PACKAGE_FULL_PATH="%SHARE_PATH%\%PACKAGE_NAME%"
set __KESCLOUD_PACKAGE_ARGUMENTS=-s

REG QUERY HKLM\Software\KasperskyLab\KESCloud /v NetAgent | FIND "0x1"
IF %ERRORLEVEL% == 1 GOTO NETAGENT
GOTO KESC
:NETAGENT
REG ADD HKLM\Software\KasperskyLab\KESCloud /v NetAgent /t REG_DWORD /f /D 1
%__KESCLOUD_PACKAGE_FULL_PATH% %__KESCLOUD_PACKAGE_ARGUMENTS%
GOTO KESC

:KESC
REG QUERY %__KESCLOUD_ROOT_KEY% /v %__KESCLOUD_KEY_NAME% | FIND "0x1"
IF %ERRORLEVEL% == 1 GOTO INSTALL
GOTO END
:INSTALL
REG ADD %__KESCLOUD_ROOT_KEY% /v %__KESCLOUD_KEY_NAME% /t REG_DWORD /f /D 1
%__KESCLOUD_PACKAGE_FULL_PATH% %__KESCLOUD_PACKAGE_ARGUMENTS%
:END

PowerShell Script

Code

###########################
# author : shebangthedolphins.net
# version : 1.0
# date : 2018.02
# role : deploy Kaspersky Endpoint Security Cloud
# other : launch it with domain admin user rights.
# updates :
#       - 1.X (x/x/xxxx) :    

$computers = New-Object System.Collections.ArrayList
[void] $computers.AddRange( ("COMPUTER15","COMPUTER85","COMPUTER86","COMPUTER98","COMPUTER16","COMPUTER19"))


Foreach ($computer in $computers)
{
    Write-Host "Work on $computer"
    ping -n 1 "$computer" | findstr "TTL"
    if ($LASTEXITCODE -eq '0')
    {
        C:\Users\administrator.shebangthedolphins\Downloads\PSTools\psexec \\"$computer" -u shebangthedolphins\administrator -p Mypassword \\SRV-DATA\share\deploy.bat
    }
    else
    {
	    write-host "$computer cannot be reached"
    }
} 
Licence Creative Commons
This websitehttp://shebangthedolphins.net is licensed to the public under a licence Creative Commons Attribution licence.
Contact :