Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$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
You can’t perform that action at this time.