powershelljmeterscriptingmdmintune

PowerShell script to download and extract Apache JMeter not working


Hello Stack Overflow community,

I am currently working on a PowerShell script to download and extract Apache JMeter on Windows using preinstalled 7-Zip. However, I am facing some issues, and I could use some assistance. Here's the script I've been working on:


# PowerShell script to download and extract Apache JMeter
        
        $jmeterUrl = "https://dlcdn.apache.org//jmeter/binaries/apache-jmeter-5.6.3.tgz"
        $jmeterExtractPath = "C:\Program Files\JMeter"
        $downloadPath = Join-Path $env:TEMP "apache-jmeter-5.6.3.tgz"
        $zipExePath = "C:\Program Files\7-Zip\7z.exe"
        
        if (-not (Test-Path -Path $jmeterExtractPath -PathType Container)) {
            New-Item -Path $jmeterExtractPath -ItemType Directory -Force
        }
        
        Invoke-WebRequest -Uri $jmeterUrl -OutFile $downloadPath
        & $zipExePath x $downloadPath -o$jmeterExtractPath -y
        Remove-Item -Path $downloadPath -Force
        
        Write-Host "Apache JMeter downloaded and extracted successfully to $jmeterExtractPath"

Unfortunately, it's not working as expected, and I'm encountering issues.

I would greatly appreciate any insights or suggestions from the community on how to resolve these issues. If there's a better approach or if there are any improvements needed in the script, please let me know.

Thank you in advance for your assistance!


Solution

  • Given you're using Windows operating system I guess you need to download the .zip archive, not the gzipped tarball.

    And "your" script can be simplified to just 2 lines:

    Invoke-WebRequest -Uri https://archive.apache.org/dist/jmeter/binaries/apache-jmeter-5.6.3.zip -OutFile jmeter.zip
    Expand-Archive -Path 'jmeter.zip'
    

    you might need to run [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 command first depending on your Windows/Powershell version

    More information: