Update Install-Filebeat.ps1

This commit is contained in:
Mathew 2025-04-14 10:38:34 +00:00
parent 3d702e686f
commit 3ac9b68025

View File

@ -1,31 +1,36 @@
# PowerShell Script to Install Filebeat 8.17.4 on Windows
# PowerShell Script to Install Filebeat 8.17.0 via MSI
# Variables
$filebeatUrl = "https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-8.17.4-windows-x86_64.zip"
$zipPath = "$env:TEMP\filebeat.zip"
$extractPath = "C:\Program Files"
$finalPath = "C:\Program Files\Filebeat"
$originalDir = "$extractPath\filebeat-8.17.4-windows-x86_64"
$msiUrl = "https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-8.17.0-windows-x86_64.msi"
$msiPath = "$env:TEMP\filebeat-8.17.0.msi"
$installPath = "C:\Program Files\Elastic\Beats\8.17.0\filebeat"
$installLog = "$env:TEMP\filebeat_install.log"
Write-Host "Downloading Filebeat..." -ForegroundColor Cyan
Invoke-WebRequest -Uri $filebeatUrl -OutFile $zipPath
Write-Host "Downloading Filebeat MSI..." -ForegroundColor Cyan
Invoke-WebRequest -Uri $msiUrl -OutFile $msiPath
Write-Host "Extracting Filebeat to $extractPath..." -ForegroundColor Cyan
Expand-Archive -Path $zipPath -DestinationPath $extractPath -Force
Write-Host "Installing Filebeat using MSI..." -ForegroundColor Cyan
Start-Process msiexec.exe -ArgumentList "/i `"$msiPath`" /qn /norestart /log `"$installLog`"" -Wait
Write-Host "Renaming extracted folder to 'Filebeat'..." -ForegroundColor Cyan
Rename-Item -Path $originalDir -NewName "Filebeat"
# Verify installation path
if (Test-Path $installPath) {
Write-Host "Filebeat installed to $installPath" -ForegroundColor Green
# Set execution policy for the current process if needed
$policy = Get-ExecutionPolicy -Scope Process
if ($policy -ne 'Unrestricted') {
Write-Host "Setting execution policy to Unrestricted for this session..." -ForegroundColor Yellow
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process -Force
# Set Execution Policy temporarily
$policy = Get-ExecutionPolicy -Scope Process
if ($policy -ne 'Unrestricted') {
Write-Host "Setting execution policy to Unrestricted for this session..." -ForegroundColor Yellow
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process -Force
}
# Install Filebeat service
Write-Host "Installing Filebeat as a Windows service..." -ForegroundColor Cyan
Push-Location $installPath
.\install-service-filebeat.ps1
Pop-Location
Write-Host "Filebeat service installed successfully!" -ForegroundColor Green
} else {
Write-Host "Filebeat was not found in the expected location: $installPath" -ForegroundColor Red
Write-Host "Check the installation log at $installLog for more information." -ForegroundColor Yellow
}
# Install Filebeat as a Windows service
Write-Host "Installing Filebeat service..." -ForegroundColor Cyan
Set-Location -Path $finalPath
.\install-service-filebeat.ps1
Write-Host "Filebeat installation completed!" -ForegroundColor Green