Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Last active May 8, 2019 05:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guitarrapc/96f6259724b723d07ed34f81564fcf99 to your computer and use it in GitHub Desktop.
Save guitarrapc/96f6259724b723d07ed34f81564fcf99 to your computer and use it in GitHub Desktop.
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if (!$currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
$me = $MyInvocation.MyCommand
$myDefinition = (Get-Command $me).Definition
$myfunction = "function $me { $myDefinition }"
$cd = (Get-Location).Path
$commands = "Set-Location $cd; $myfunction; Write-Host 'Running $me'; $me; Pause"
$bytes = [System.Text.Encoding]::Unicode.GetBytes($commands)
$encode = [Convert]::ToBase64String($bytes)
$argumentList = "-NoProfile","-EncodedCommand", $encode
Write-Warning "Detected you are not runnning with Admin Priviledge."
$proceed = Read-Host "Required elevated priviledge to add exlusion to Windows Defender. Do you proceed? (y/n)"
if ($proceed -ceq "y") {
$p = Start-Process -Verb RunAs powershell.exe -ArgumentList $argumentList -Wait -PassThru
return $p.ExitCode
}
else {
Write-Host "Cancel evelated."
return 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment