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