Last active
May 8, 2019 05:21
-
-
Save guitarrapc/96f6259724b723d07ed34f81564fcf99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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