Skip to content

Commit

Permalink
Fix for admin elevation code (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
fullmetalcache authored Mar 9, 2021
1 parent bf84d51 commit af11f1b
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions agent/install-sysmon-beats.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,23 @@ param (

if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
$arguments = "& '" +$myinvocation.mycommand.definition + "'", $args
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
# Use param values instead of $args because $args doesn't appear to get populated if param values are specified
# Also set the ExecutionPolicy to Bypass otherwise this will likely fail as script
# execution is disabled by default.
$arguments = "-ExecutionPolicy", "Bypass", "-File", $myinvocation.mycommand.definition, $ESHost, $ESPort
if($ESUsername)
{
# Only add this argument if the user provided it, otherwise it will be blank and will cause an error
$arguments += $ESUsername
}
if($ESPassword)
{
# Only add this argument if the user provided it, otherwise it will be blank and will cause an error
$arguments += $ESPassword
}

Start-Process -FilePath powershell -Verb runAs -ArgumentList $arguments
Break
}

if (-not (Test-Path "$Env:programfiles\Sysmon" -PathType Container)) {
Expand Down

0 comments on commit af11f1b

Please sign in to comment.