[CmdletBinding()] param ( [Parameter(Mandatory=$true)] [String] $InstallerUrl ) <# .SYNOPSIS Silently installs the ActivTrak agent. .DESCRIPTION This script silently downloads and installs the ActivTrak agent from a given URL. Installer URLs expire after 72 hours. Generate a new installer URL using the instructions on this page: https://support.activtrak.com/hc/en-us/articles/360052228952-Deploy-Via-PowerShell-Script .PARAMETER InstallerUrl The URL from which to download the ActivTrak installer .LINK https://support.activtrak.com/hc/en-us/articles/360052228952-Deploy-Via-PowerShell-Script #> process { # Download Write-Host "Downloading application..." ## Create a WebRequest to read only headers [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12 $Request = [System.Net.HttpWebRequest]::Create($InstallerUrl) $Request.Method = "HEAD" try { $Response = $Request.GetResponse() $ContentDisposition = $Response.Headers["Content-Disposition"] $Response.Close() } catch { throw "Failed to retrieve response headers. $_" } if ($ContentDisposition) { $InstallerName = [System.Net.WebUtility]::UrlDecode(($ContentDisposition -replace '.*filename=([^;]+).*', '$1')) $InstallerPath = Join-Path -Path $env:TEMP -ChildPath $InstallerName ## Download file to the full path try { # Invoke-WebRequest -Uri $InstallerUrl -OutFile $InstallerPath # Use Legacy WebClient for compatibility (New-Object Net.WebClient).DownloadFile($InstallerUrl, $InstallerPath) } catch { throw "Download failed. $_" } # Install try { Write-Host "Installing application..." $ExitCode = (Start-Process -FilePath "msiexec.exe" -ArgumentList "/i `"$($InstallerPath)`" /qn /l*v `"$($InstallerPath).log`"" -Wait -PassThru).ExitCode } catch { throw "Failed installing application. $_" } } else { Write-Host "Content-Disposition header not found. Please contact ActivTrak Support at Support@ActivTrak.com if problem persists." } } end { # Clean up Write-Host "Removing package download from '$InstallerPath'" Remove-Item -Path $InstallerPath -Force switch ($ExitCode) { 0 { Write-Host "Installation succeeded."; break } 3010 { Write-Host "A reboot is required to complete installation."; break } default { Write-Error "Installation failed with exit code $ExitCode. For help see https://learn.microsoft.com/en-us/windows/win32/msi/error-codes" } } }