|
3 | 3 | # Script ver 2025071001 |
4 | 4 |
|
5 | 5 | # Changelog |
| 6 | +# 2025-07-25: - Fix Downloading from git function returns too much info |
6 | 7 | # 2025-07-10: - Add error message on MSI install failure |
7 | 8 | # 2025-07-07: - Update default collectors for windows_exporter 0.31+ |
8 | 9 | # 2025-03-24: - Re-enable firewall exception, disabled by upstream |
@@ -55,8 +56,9 @@ function DownloadGitRelease { |
55 | 56 | $releasesUri = "https://api.github.com/repos/$git_org/$git_repo/releases/latest" |
56 | 57 | $downloadUri = ((Invoke-RestMethod -Method GET -Uri $releasesUri).assets | Where-Object name -like $filenamePattern ).browser_download_url |
57 | 58 | $MSI_FILE = Join-Path -Path $script_path -ChildPath $(Split-Path -Path $downloadUri -Leaf) |
58 | | - Write-Output "Downloading github release to $MSI_FILE" |
| 59 | + Write-Host "Downloading github release to $MSI_FILE" |
59 | 60 | Invoke-WebRequest -Uri $downloadUri -Out $MSI_FILE |
| 61 | + return $MSI_FILE |
60 | 62 | } |
61 | 63 |
|
62 | 64 |
|
@@ -189,7 +191,12 @@ try { |
189 | 191 | Write-Output "Found windows_exporter in $MSI_FILE" |
190 | 192 | } catch { |
191 | 193 | Write-Output "No windows_exporter msi file found. Trying to download a copy from github" |
192 | | - DownLoadGitRelease |
| 194 | + try { |
| 195 | + $MSI_FILE = DownLoadGitRelease |
| 196 | + } catch { |
| 197 | + Write-Error "Cannot download git release" |
| 198 | + exit 1 |
| 199 | + } |
193 | 200 | } |
194 | 201 |
|
195 | 202 |
|
@@ -217,11 +224,12 @@ if ($null -ne $app) { |
217 | 224 | $app.Uninstall() | Out-Null |
218 | 225 | } |
219 | 226 |
|
| 227 | +$MSI_ARGS="/passive /i $MSI_FILE ENABLED_COLLECTORS=$COLLECTORS LISTEN_PORT=$LISTEN_PORT ADDLOCAL=$ADD_LOCAL" |
220 | 228 | Write-Output "Installing windows exporter with following command line:" |
221 | | -Write-Output "msiexec.exe /passive /i $MSI_FILE ENABLED_COLLECTORS=$COLLECTORS LISTEN_PORT=$LISTEN_PORT ADDLOCAL=$ADD_LOCAL" |
222 | | -msiexec.exe /passive /i $MSI_FILE ENABLED_COLLECTORS="$COLLECTORS" LISTEN_PORT=$LISTEN_PORT ADDLOCAL=$ADD_LOCAL |
223 | | -if ($LASTEXITCODE -ne 0) { |
224 | | - Write-Output "Failed to install $MSI_FILE - See event logs" |
| 229 | +Write-Output "msiexec.exe $MSI_ARGS" |
| 230 | +$exit_code = (Start-Process -FilePath msiexec.exe -ArgumentList $MSI_ARGS -Wait -PassThru).ExitCode |
| 231 | +if ($exit_code -ne 0) { |
| 232 | + Write-Output "Failed to install $MSI_FILE - See event logs, exit_code = $exit_code" |
225 | 233 | Start-Sleep -s 15 |
226 | 234 | exit 1 |
227 | 235 | } |
|
0 commit comments