Skip to content

Commit

Permalink
Make script compatible with older ps
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-gr committed Jan 14, 2025
1 parent 24fca7a commit e6cc25b
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions .buildkite/scripts/install_sysmon.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,29 @@ if (!(Test-Path $tempFolder)) {
}

$ProgressPreference = 'SilentlyContinue'
function ParseErrorForResponseBody($Error) {
if ($PSVersionTable.PSVersion.Major -lt 6) {
if ($Error.Exception.Response) {
$Reader = New-Object System.IO.StreamReader($Error.Exception.Response.GetResponseStream())
$Reader.BaseStream.Position = 0
$Reader.DiscardBufferedData()
$ResponseBody = $Reader.ReadToEnd()
if ($ResponseBody.StartsWith('{')) {
$ResponseBody = $ResponseBody | ConvertFrom-Json
}
return $ResponseBody
}
}
else {
return $Error.ErrorDetails.Message
}
}

try {
Invoke-WebRequest -Uri $downloadUrl -OutFile "$tempFolder\Sysmon.zip" -UseBasicParsing
} catch {
$result = $_.Exception.Response.GetResponseStream()
$reader = New-Object System.IO.StreamReader($result)
$reader.BaseStream.Position = 0
$reader.DiscardBufferedData()
$reader.ReadToEnd()
$result = Invoke-WebRequest -Uri $downloadUrl -OutFile "$tempFolder\Sysmon.zip" -UseBasicParsing
}
catch {
ParseErrorForResponseBody($_)
exit 1
}

Expand Down

0 comments on commit e6cc25b

Please sign in to comment.