Skip to content

Instantly share code, notes, and snippets.

@MiroXP
Created June 22, 2022 09:57
Show Gist options
  • Save MiroXP/e8aafd778de66ee18974c52bc0673ae4 to your computer and use it in GitHub Desktop.
Save MiroXP/e8aafd778de66ee18974c52bc0673ae4 to your computer and use it in GitHub Desktop.
Function Check-Administrator {
    $currentPrincipal = New-Object Security.Principal.WindowsPrincipal( [Security.Principal.WindowsIdentity]::GetCurrent() )
    if ($currentPrincipal.IsInRole( [Security.Principal.WindowsBuiltInRole]::Administrator )) {
        return $true
    } else {
        return $false
    }
}
 
#Check for elevated mode
if (-not (Check-Administrator)) {
        Write-Warning "This script needs to be executed in elevated mode. Start the Shell as an Administrator and try again."
        $Error.Clear()
        Exit
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment