Jump to content

Установка агента через GPO


Recommended Posts

Скачиваем с Kaspersky Security для бизнеса Network Agent для Windows.

Распаковываем архив и достаём из него файл Kaspersky Network Agent.msi.

Сохраняем скрипт рядом с файлом Kaspersky Network Agent.msi и запускаем.

make-klnag4GPO.ps1 <имя сервера администрирования> (по умолчанию скрипт нацелен на 127.0.0.1)

После успешного завершения скрипта добавляем в GPO на установку.

<#

 #>
[CmdletBinding()]
PARAM(
    [parameter(Position = 0)]
    [String]$SERVERADDRESS = "127.0.0.1",
    [parameter(Position = 1)]
    [String]$PATH = "Kaspersky Network Agent.msi",
    
    [String]$Tags = "KLNagGPO"
     
)#PARAM
 
Begin {     
}

Process {
    $windowsInstaller = New-Object -ComObject WindowsInstaller.Installer
    function Set-MSIProperty {
        Param (
            [string] $Property,
            [string] $Value
        )
        try {
            $QueryView = "SELECT Value FROM Property WHERE Property = '$Property'"
            $View = $MSIDatabase.GetType().InvokeMember(
                "OpenView",
                "InvokeMethod",
                $Null,
                $MSIDatabase,
                     ($QueryView)
            )
 
            $View.GetType().InvokeMember("Execute", "InvokeMethod", $Null, $View, $Null)
            $Record = $View.GetType().InvokeMember("Fetch", "InvokeMethod", $null, $View, $null)
            [System.Runtime.Interopservices.Marshal]::ReleaseComObject($View) | Out-Null
            if ([string]::IsNullOrEmpty($Record)) {
                $QuerySet = "INSERT INTO ``Property`` (``Property``,``Value``) VALUES ('$Property', '$Value')"
            }
            else {
                [System.Runtime.Interopservices.Marshal]::ReleaseComObject($Record) | Out-Null
                $QuerySet = "UPDATE Property SET Value = '$Value' WHERE Property = '$Property'"
            }
             
            $View = $MSIDatabase.GetType().InvokeMember(
                "OpenView",
                "InvokeMethod",
                $Null,
                $MSIDatabase,
                     ($QuerySet)
            )
            $View.GetType().InvokeMember("Execute", "InvokeMethod", $Null, $View, $Null)
            $View.GetType().InvokeMember("Close", "InvokeMethod", $Null, $View, $Null)
            [System.Runtime.Interopservices.Marshal]::ReleaseComObject($View) | Out-Null
        }
        catch {
            Write-Warning -Message "Set-MSIProperty"
            Write-Warning -Message $_
            Write-Warning -Message $_.ScriptStackTrace
        }
    }

    try {
        $MSIDatabase = $windowsInstaller.OpenDatabase($(Get-ChildItem  $PATH).FullName, 1)
    
        <#
        # LIMITUI              = 1
        # EULA                 = 1
        # SERVERADDRESS        = 127.0.0.1
        # DONT_USE_ANSWER_FILE = 1
        # NAGENTTAGS           = KLNagGPO
        #>
        Set-MSIProperty "EULA"                  "1"
        Set-MSIProperty "LIMITUI"               "1"
        Set-MSIProperty "DONT_USE_ANSWER_FILE"  "1"
        Set-MSIProperty "SERVERADDRESS"         $SERVERADDRESS
        Set-MSIProperty "NAGENTTAGS"            $Tags
 
        
        $MSIDatabase.GetType().InvokeMember("Commit", "InvokeMethod", $Null, $MSIDatabase, $Null)
        [System.Runtime.Interopservices.Marshal]::ReleaseComObject($MSIDatabase) | Out-Null 
    }
    catch {
        Write-Error "Error!!!"
    }
    
    [System.Runtime.Interopservices.Marshal]::ReleaseComObject($WindowsInstaller) | Out-Null 
    [System.GC]::Collect()
}
End {   
}

 

  • Like 2
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now


×
×
  • Create New...