Powershell script for deploying beats modules. Can be used with group policy.
Hopefully this can be of use to anyone else starting out with the ELK stack.
$beats = "Metricbeat", "Heartbeat", "Auditbeat", "Winlogbeat", "Packetbeat"
# Path to remote location containing beats folders with all files inside. File path can be a network share such as \\server\beatsfolder
# Download your files from https://www.elastic.co/downloads/beats/ as Windows Zip files and extract the folders and name them
# Metricbeat, Heartbeat, Auditbeat, Winlogbeat, Packetbeat accordingly. Place these folder in the same directory in the remote location.
# This will copy each folder into the client's Program Files directory.
# Replace/Modify the *beat.yml file with the config you need.
$beatslocation = "<remote file location here>"
foreach ($beat in $beats){
$beatlower = $beat.ToLower()
if ((Test-Path -Path "C:\Program Files\$beat\") -eq $false){
# Pull all files from directory if path does not exist
copy "$beatslocation\$beat\" -Recurse "C:\Program Files\$beat\" -Force
& "C:\Program Files\$beat\install-service-$beatlower.ps1"
Start-Service $beat
}
else
{
# Update Config if path exists and restart service. Packetbeat has an issue where it does not properly
# stop/restart, so it kills the process then restarts it.
copy "$beatslocation\$beat\$beatlower.yml" "C:\Program Files\$beat\$beatlower.yml" -Force
if ($beat -eq "Packetbeat"){
if ((Get-Service | Select-Object name) -contains $beatlower) {
Get-Service | where name -eq $beatlower | kill -Force
Start-Service $beatlower
}
else {
Start-Service $beatlower
}
}
else {
Restart-Service $beat
}
}
}