forked from CrowdStrike/falcon-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
falcon_windows_install.ps1
executable file
·603 lines (520 loc) · 23.5 KB
/
falcon_windows_install.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
<#
.SYNOPSIS
Download and install the CrowdStrike Falcon Sensor for Windows
.DESCRIPTION
Uses the CrowdStrike Falcon APIs to check the sensor version assigned to a Windows Sensor Update policy,
downloads that version, then installs it on the local machine. By default, once complete, the script
deletes itself and the downloaded installer package. The individual steps and any related error messages
are logged to 'Windows\Temp\InstallFalcon.log' unless otherwise specified.
Script options can be passed as parameters or defined in the param() block. Default values are listed in
the parameter descriptions.
The script must be run as an administrator on the local machine in order for the Falcon Sensor installation
to complete, and the OAuth2 API Client being used requires 'sensor-update-policies:read' and
'sensor-download:read' permissions.
.PARAMETER FalconCloud
CrowdStrike Falcon OAuth2 API Hostname [default: autodiscover]
.PARAMETER FalconClientId
CrowdStrike Falcon OAuth2 API Client Id [Required]
.PARAMETER FalconClientSecret
CrowdStrike Falcon OAuth2 API Client Secret [Required]
.PARAMETER FalconCid
Manually specify CrowdStrike Customer ID (CID) [default: $null]
.PARAMETER MemberCid
Member CID, used only in multi-CID ("Falcon Flight Control") configurations and with a parent management CID [default: $null]
.PARAMETER SensorUpdatePolicyName
Sensor Update Policy name to check for assigned sensor version [default: 'platform_default']
.PARAMETER InstallParams
Additional Sensor installation parameters. Script parameters should be used instead when supported. [default: '/install /quiet /noreboot' ]
.PARAMETER LogPath
Script log location [default: 'Windows\Temp\InstallFalcon.log']
.PARAMETER DeleteInstaller
Delete sensor installer package when complete [default: $true]
.PARAMETER DeleteScript
Delete script when complete [default: $false]
.PARAMETER ProvToken
Provisioning token to use for sensor installation [default: $null]
.PARAMETER ProvWaitTime
Time to wait, in seconds, for sensor to provision [default: 1200]
.PARAMETER Tags
A comma-separated list of tags to apply to the host after sensor installation [default: $null]
.PARAMETER ProxyHost
The proxy host for the sensor to use when communicating with CrowdStrike [default: $null]
.PARAMETER ProxyPort
The proxy port for the sensor to use when communicating with CrowdStrike [default: $null]
.PARAMETER ProxyDisable
By default, the Falcon sensor for Windows automatically attempts to use any available proxy connections when it connects to the CrowdStrike cloud.
This parameter forces the sensor to skip those attempts and ignore any proxy configuration, including Windows Proxy Auto Detection.
.PARAMETER Verbose
Enable verbose logging
.EXAMPLE
PS>.\falcon_windows_install.ps1 -FalconClientId <string> -FalconClientSecret <string>
Run the script and define 'FalconClientId' and 'FalconClientSecret' during runtime. All other
parameters will use their default values.
.EXAMPLE
PS>.\falcon_windows_install.ps1
Run the script and use all values that were previously defined within the script.
.NOTES
Updated 2021-10-22 to include 'sensor_version' property when matching policy to sensor installer package.
#>
#Requires -Version 3.0
[CmdletBinding()]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', 'DeleteInstaller')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', 'DeleteScript')]
param(
[Parameter(Position = 1)]
[ValidateSet('autodiscover', 'us-1', 'us-2', 'eu-1', 'us-gov-1')]
[string] $FalconCloud = 'autodiscover',
[Parameter(Position = 2)]
[string] $FalconClientId,
[Parameter(Position = 3)]
[string] $FalconClientSecret,
[Parameter(Position = 4)]
[string] $MemberCid,
[Parameter(Position = 5)]
[string] $SensorUpdatePolicyName,
[Parameter(Position = 6)]
[string] $InstallParams,
[Parameter(Position = 7)]
[string] $LogPath,
[Parameter(Position = 8)]
[bool] $DeleteInstaller = $true,
[Parameter(Position = 9)]
[bool] $DeleteScript = $false,
[Parameter(Position = 10)]
[string] $ProvToken,
[Parameter(Position = 11)]
[int] $ProvWaitTime = 1200,
[Parameter(Position = 12)]
[string] $Tags,
[Parameter(Position = 13)]
[ValidatePattern('\w{32}-\w{2}')]
[string] $FalconCid,
[Parameter(Position = 14)]
[string] $ProxyHost,
[Parameter(Position = 15)]
[int] $ProxyPort,
[Parameter(Position = 16)]
[switch] $ProxyDisable
)
begin {
if ($PSVersionTable.PSVersion -lt '3.0')
{ throw "This script requires a miniumum PowerShell 3.0" }
$ScriptName = $MyInvocation.MyCommand.Name
$ScriptPath = if (!$PSScriptRoot) {
Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
}
else {
$PSScriptRoot
}
function Write-FalconLog ([string] $Source, [string] $Message, [bool] $stdout = $true) {
$Content = @(Get-Date -Format 'yyyy-MM-dd hh:MM:ss')
if ($Source -notmatch '^(StartProcess|Delete(Installer|Script))$' -and
$Falcon.ResponseHeaders.Keys -contains 'X-Cs-TraceId') {
$Content += , "[$($Falcon.ResponseHeaders.Get('X-Cs-TraceId'))]"
}
"$(@($Content + $Source) -join ' '): $Message" | Out-File -FilePath $LogPath -Append -Encoding utf8
if ($stdout) {
Write-Output $Message
}
}
function Write-VerboseLog ([psobject] $VerboseInput, [string] $PreMessage) {
# Determine if the input is a string or an object
if ($VerboseInput -is [string]) {
$message = $VerboseInput
}
else {
$message = $VerboseInput | ConvertTo-Json -Depth 10
}
# If a pre-message is provided, add it to the beginning of the message
if ($PreMessage) {
$message = "$PreMessage`r`n$message"
}
# Write Verbose
Write-Verbose $message
# Write to log file, but not stdout
Write-FalconLog -Source 'VERBOSE' -Message $message -stdout $false
}
function Get-FalconCloud ([string] $xCsRegion) {
$Output = switch ($xCsRegion) {
'autodiscover' { 'https://api.crowdstrike.com'; break }
'us-1' { 'https://api.crowdstrike.com'; break }
'us-2' { 'https://api.us-2.crowdstrike.com'; break }
'eu-1' { 'https://api.eu-1.crowdstrike.com'; break }
'us-gov-1' { 'https://api.laggar.gcw.crowdstrike.com'; break }
default { throw "Provided region $xCsRegion is invalid. Please set FalconCloud to a valid region or 'autodiscover'"; break }
}
return $Output
}
function Invoke-FalconAuth([hashtable] $WebRequestParams, [string] $BaseUrl, [hashtable] $Body, [string] $FalconCloud) {
$Headers = @{'Accept' = 'application/json'; 'Content-Type' = 'application/x-www-form-urlencoded'; 'charset' = 'utf-8' }
$Headers.Add('User-Agent', 'crowdstrike-falcon-scripts/1.3.3')
try {
$response = Invoke-WebRequest @WebRequestParams -Uri "$($BaseUrl)/oauth2/token" -UseBasicParsing -Method 'POST' -Headers $Headers -Body $Body
$content = ConvertFrom-Json -InputObject $response.Content
Write-VerboseLog -VerboseInput $content -PreMessage 'Invoke-FalconAuth - $content:'
if ([string]::IsNullOrEmpty($content.access_token)) {
$message = 'Unable to authenticate to the CrowdStrike Falcon API. Please check your credentials and try again.'
throw $message
}
$Headers.Add('Authorization', "bearer $($content.access_token)")
}
catch {
# Handle redirects
Write-Verbose "Invoke-FalconAuth - CAUGHT EXCEPTION - `$_.Exception.Message`r`n$($_.Exception.Message)"
$response = $_.Exception.Response
if (!$response) {
$message = "Unhandled error occurred while authenticating to the CrowdStrike Falcon API. Error: $($_.Exception.Message)"
Write-FalconLog -Source 'Invoke-FalconAuth' -Message $message
throw $message
}
if ($response.StatusCode -in @(301, 302, 303, 307, 308)) {
# If autodiscover is enabled, try to get the correct cloud
if ($FalconCloud -eq 'autodiscover') {
if ($response.Headers.Contains('X-Cs-Region')) {
$region = $response.Headers.GetValues('X-Cs-Region')[0]
Write-Verbose "Received a redirect to $region. Setting FalconCloud to $region"
}
else {
$message = 'Received a redirect but no X-Cs-Region header was provided. Unable to autodiscover the FalconCloud. Please set FalconCloud to the correct region.'
Write-FalconLog -Source 'Invoke-FalconAuth' -Message $message
throw $message
}
$BaseUrl = Get-FalconCloud($region)
$BaseUrl, $Headers = Invoke-FalconAuth -WebRequestParams $WebRequestParams -BaseUrl $BaseUrl -Body $Body -FalconCloud $FalconCloud
}
else {
$message = "Received a redirect. Please set FalconCloud to 'autodiscover' or the correct region."
Write-FalconLog -Source 'Invoke-FalconAuth' -Message $message
throw $message
}
}
else {
$message = "Received a $($response.StatusCode) response from $($BaseUrl)oauth2/token. Please check your credentials and try again. Error: $($response.StatusDescription)"
Write-FalconLog -Source 'Invoke-FalconAuth' -Message $message
throw $message
}
}
return $BaseUrl, $Headers
}
function Test-FalconCredential([string] $FalconClientId , [string] $FalconClientSecret ) {
if ($FalconClientId -and $FalconClientSecret) {
return $true
}
else {
return $false
}
}
$WinSystem = [Environment]::GetFolderPath('System')
$WinTemp = $WinSystem -replace 'system32', 'Temp'
if (!$LogPath) {
$LogPath = Join-Path -Path $WinTemp -ChildPath 'InstallFalcon.log'
}
function Format-403Error([string] $url, [hashtable] $scope) {
$message = "Insufficient permission error when calling $($url). Verify the following scopes are included in the API key:"
foreach ($key in $scope.Keys) {
$message += "`r`n`t '$($key)' with: $($scope[$key])"
}
return $message
}
function Format-FalconResponseError($errors) {
$message = ''
foreach ($error in $errors) {
$message += "`r`n`t $($error.message)"
}
return $message
}
function Get-ResourceContent([hashtable] $WebRequestParams, [string] $url, [string] $logKey, [hashtable] $scope, [string] $errorMessage) {
try {
$response = Invoke-WebRequest @WebRequestParams -Uri $url -UseBasicParsing -Method 'GET' -MaximumRedirection 0
$content = ConvertFrom-Json -InputObject $response.Content
Write-VerboseLog -VerboseInput $content -PreMessage 'Get-ResourceContent - $content:'
if ($content.errors) {
$message = "Error when getting content: "
$message += Format-FalconResponseError -errors $content.errors
Write-FalconLog $logKey $message
throw $message
}
if ($content.resources) {
return $content.resources
}
else {
$message = $errorMessage
throw $message
}
}
catch {
Write-VerboseLog -VerboseInput $_.Exception.Message -PreMessage 'Get-ResourceContent - CAUGHT EXCEPTION - $_.Exception.Message:'
$response = $_.Exception.Response
if (!$response) {
$message = "Unhandled error occurred. Error: $($_.Exception.Message)"
throw $message
}
if ($response.StatusCode -eq 403) {
$message = Format-403Error -url $url -scope $scope
Write-FalconLog $logKey $message
throw $message
}
else {
$message = "Received a $($response.StatusCode) response from ${url}. Error: $($response.StatusDescription)"
Write-FalconLog $logKey $message
throw $message
}
}
}
function Get-InstallerHash ([string] $Path) {
$Output = if (Test-Path $Path) {
$Algorithm = [System.Security.Cryptography.HashAlgorithm]::Create("SHA256")
$Hash = [System.BitConverter]::ToString(
$Algorithm.ComputeHash([System.IO.File]::ReadAllBytes($Path)))
if ($Hash) {
$Hash.Replace('-', '')
}
else {
$null
}
}
return $Output
}
function Invoke-FalconDownload ([hashtable] $WebRequestParams, [string] $url, [string] $Outfile) {
try {
$ProgressPreference = 'SilentlyContinue'
$response = Invoke-WebRequest @WebRequestParams -Uri $url -UseBasicParsing -Method 'GET' -OutFile $Outfile
}
catch {
$response = $_.Exception.Response
if (!$response) {
$message = "Unhandled error occurred. Error: $($_.Exception.Message)"
Write-FalconLog 'DownloadFile' $message
throw $message
}
if ($response.StatusCode -eq 403) {
$scope = @{
'Sensor Download' = @('Read')
}
$message = Format-403Error -url $url -scope $scope
Write-FalconLog 'Permissions' $message
throw $message
}
else {
$message = "Received a $($response.StatusCode) response from ${url}. Error: $($response.StatusDescription)"
Write-FalconLog 'DownloadFile' $message
throw $message
}
}
}
if (!$SensorUpdatePolicyName) {
$SensorUpdatePolicyName = 'platform_default'
}
if (!$InstallParams) {
$InstallParams = '/install /quiet /noreboot'
}
}
process {
if (([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(
[Security.Principal.WindowsBuiltInRole]::Administrator) -eq $false) {
$message = 'Unable to proceed without administrative privileges'
Write-FalconLog 'CheckAdmin' $message
throw $message
}
elseif (Get-Service | Where-Object { $_.Name -eq 'CSFalconService' }) {
$message = "'CSFalconService' running. Falcon sensor is already installed."
Write-FalconLog 'CheckService' $message
exit 0
}
else {
$credsProvided = Test-FalconCredential $FalconClientId $FalconClientSecret
if ([Net.ServicePointManager]::SecurityProtocol -notmatch 'Tls12') {
try {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
}
catch {
$message = $_
Write-FalconLog 'TlsCheck' $message
throw $message
}
}
}
# Hashtable for common Invoke-WebRequest parameters
$WebRequestParams = @{}
# Configure proxy based on arguments
$proxy = ""
if ($ProxyHost) {
Write-Output "Proxy settings detected in arguments, using proxy settings to communicate with the CrowdStrike api"
if ($ProxyHost) {
$proxy_host = $ProxyHost.Replace("http://", "").Replace("https://", "")
Write-FalconLog -Source "Proxy" -Message "Proxy host ${proxy_host} found in arguments" -stdout $true
}
if ($ProxyPort) {
Write-FalconLog -Source "Proxy" -Message "Proxy port ${ProxyPort} found in arguments" -stdout $true
$proxy = "http://${proxy_host}:${ProxyPort}"
}
else {
$proxy = "http://${proxy_host}"
}
$proxy = $proxy.Replace("'", "").Replace("`"", "")
Write-FalconLog -Source "Proxy" -Message "Using proxy ${proxy} to communicate with the CrowdStrike Apis" -stdout $true
}
if ($proxy) {
$WebRequestParams.Add('Proxy', $proxy)
}
# Configure OAuth2 authentication
if ($credsProvided) {
$BaseUrl = Get-FalconCloud $FalconCloud
$Body = @{}
$Body['client_id'] = $FalconClientId
$Body['client_secret'] = $FalconClientSecret
if ($MemberCid) {
$Body['member_cid'] = $MemberCid
}
$BaseUrl, $Headers = Invoke-FalconAuth -WebRequestParams $WebRequestParams -BaseUrl $BaseUrl -Body $Body -FalconCloud $FalconCloud
$Headers['Content-Type'] = 'application/json'
$WebRequestParams.Add('Headers', $Headers)
}
else {
$message = 'Unable to proceed without valid API credentials. Ensure you pass the required parameters or define them in the script.'
Write-FalconLog 'CheckCredentials' $message
throw $message
}
# Get CCID from API if not provided
if (!$FalconCid) {
Write-FalconLog 'GetCcid' 'No CCID provided. Attempting to retrieve from the CrowdStrike Falcon API.'
$url = "${BaseUrl}/sensors/queries/installers/ccid/v1"
$ccid_scope = @{
'Sensor Download' = @('Read')
}
$ccid = Get-ResourceContent -WebRequestParams $WebRequestParams -url $url -logKey 'GetCcid' -scope $ccid_scope -errorMessage "Unable to grab CCID from the CrowdStrike Falcon API."
$message = "Retrieved CCID: $ccid"
Write-FalconLog 'GetCcid' $message
$InstallParams += " CID=$ccid"
}
else {
$message = "Using provided CCID: $FalconCid"
Write-FalconLog 'GetCcid' $message
$InstallParams += " CID=$FalconCid"
}
# Get sensor version from policy
$message = "Retrieving sensor policy details for '$($SensorUpdatePolicyName)'"
Write-FalconLog 'GetPolicy' $message
$filter = "platform_name:'Windows'+name.raw:'$($SensorUpdatePolicyName)'"
$url = "${BaseUrl}/policy/combined/sensor-update/v2?filter=$([System.Web.HttpUtility]::UrlEncode($filter)))"
$policy_scope = @{
'Sensor update policies' = @('Read')
}
$policyDetails = Get-ResourceContent -WebRequestParams $WebRequestParams -url $url -logKey 'GetPolicy' -scope $policy_scope -errorMessage "Unable to fetch policy details from the CrowdStrike Falcon API."
$policyId = $policyDetails.id
$build = $policyDetails[0].settings.build
$version = $policyDetails[0].settings.sensor_version
# Make sure we got a version from the policy
if (!$version) {
$message = "Unable to retrieve sensor version from policy '$($SensorUpdatePolicyName)'. Please check the policy and try again."
Write-FalconLog 'GetPolicy' $message
throw $message
}
$message = "Retrieved sensor policy details: Policy ID: $policyId, Build: $build, Version: $version"
Write-FalconLog 'GetPolicy' $message
# Get installer details based on policy version
$message = "Retrieving installer details for sensor version: '$($version)'"
Write-FalconLog 'GetInstaller' $message
$encodedFilter = [System.Web.HttpUtility]::UrlEncode("platform:'windows'+version:'$($version)'")
$url = "${BaseUrl}/sensors/combined/installers/v1?filter=${encodedFilter}"
$installer_scope = @{
'Sensor Download' = @('Read')
}
$installerDetails = Get-ResourceContent -WebRequestParams $WebRequestParams -url $url -logKey 'GetInstaller' -scope $installer_scope -errorMessage "Unable to fetch installer details from the CrowdStrike Falcon API."
if ( $installerDetails.sha256 -and $installerDetails.name ) {
$cloudHash = $installerDetails.sha256
$cloudFile = $installerDetails.name
$message = "Found installer: ($cloudFile) with sha256: '$cloudHash'"
Write-FalconLog 'GetInstaller' $message
}
else {
$message = "Failed to retrieve installer details."
Write-FalconLog 'GetInstaller' $message
throw $message
}
# Download the installer
$localFile = Join-Path -Path $WinTemp -ChildPath $cloudFile
Write-FalconLog 'DownloadFile' "Downloading installer to: '$localFile'"
$url = "${BaseUrl}/sensors/entities/download-installer/v1?id=$cloudHash"
Invoke-FalconDownload -WebRequestParams $WebRequestParams -url $url -Outfile $localFile
if (Test-Path $localFile) {
$localHash = Get-InstallerHash -Path $localFile
$message = "Successfull downloaded installer '$localFile' ($localHash)"
Write-FalconLog 'DownloadFile' $message
}
else {
$message = "Failed to download installer."
Write-FalconLog 'DownloadFile' $message
throw $message
}
# Compare the hashes prior to installation
if ($cloudHash -ne $localHash) {
$message = "Hash mismatch on download (Local: $localHash, Cloud: $cloudHash)"
Write-FalconLog 'CheckHash' $message
throw $message
}
# Additional parameters
if ($ProvToken) {
$InstallParams += " ProvToken=$ProvToken"
}
if ($Tags) {
$InstallParams += " GROUPING_TAGS=$Tags"
}
if ($ProxyHost) {
$InstallParams += " APP_PROXYNAME=$ProxyHost"
}
if ($ProxyPort) {
$InstallParams += " APP_PROXYPORT=$ProxyPort"
}
# Disable proxy when switch is used
if ($ProxyDisable) {
$InstallParams += " PROXYDISABLE=0"
}
$InstallParams += " ProvWaitTime=$ProvWaitTime"
# Begin installation
Write-FalconLog 'Installer' 'Installing Falcon Sensor...'
Write-FalconLog 'StartProcess' "Starting installer with parameters: '$InstallParams'"
$process = (Start-Process -FilePath $LocalFile -ArgumentList $InstallParams -PassThru -ErrorAction SilentlyContinue)
Write-FalconLog 'StartProcess' "Started '$LocalFile' ($($process.Id))"
Write-FalconLog 'StartProcess' "Waiting for the installer process to complete with PID ($($process.Id))"
Wait-Process -Id $process.Id
Write-FalconLog 'StartProcess' "Installer process with PID ($($process.Id)) has completed"
# Check the exit code
if ($process.ExitCode -ne 0) {
Write-VerboseLog -VerboseInput $process -PreMessage 'PROCESS EXIT CODE ERROR - $process:'
if ($process.ExitCode -eq 1244) {
$message = "Exit code 1244: Falcon was unable to communicate with the CrowdStrike cloud. Please check your installation token and try again."
Write-FalconLog 'InstallerProcess' $message
throw $message
}
else {
$errOut = $process.StandardError.ReadToEnd()
$message = "Falcon installer exited with code $($process.ExitCode). Error: $errOut"
Write-FalconLog 'InstallerProcess' $message
throw $message
}
}
@('DeleteInstaller', 'DeleteScript') | ForEach-Object {
if ((Get-Variable $_).Value -eq $true) {
$FilePath = if ($_ -eq 'DeleteInstaller') {
$LocalFile
}
else {
Join-Path -Path $ScriptPath -ChildPath $ScriptName
}
Remove-Item -Path $FilePath -Force
if (Test-Path $FilePath) {
Write-FalconLog $_ "Failed to delete '$FilePath'"
}
else {
Write-FalconLog $_ "Deleted '$FilePath'"
}
}
}
Write-FalconLog 'InstallerProcess' 'Falcon sensor installed successfully.'
}
end {
Write-FalconLog 'EndScript' 'Script completed.'
$message = "`r`nSee the full log contents at: '$($LogPath)'"
Write-Output $message
}