Last active
December 24, 2015 01:39
-
-
Save lukesampson/6725722 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
# quick exec: | |
# iex (new-object net.webclient).downloadstring('https://gist.github.com/lukesampson/6725722/raw/sudo_diag.ps1') | |
$id = [Security.Principal.WindowsIdentity]::GetCurrent() | |
"current user: $($id.name)" | |
$elevated = ([Security.Principal.WindowsPrincipal]($id)).isinrole("Administrators") | |
"elevated: $elevated" | |
$name = $id.name -replace '^[^\\]*\\', '' | |
$res = gwmi win32_groupuser | ? { $_.partcomponent -match "name=`"$name`"" } | |
"gwmi groups:" | |
$res | % { " $($_.groupcomponent)" } | |
$sig = '[DllImport("advapi32.dll", SetLastError=true)] | |
public static extern bool GetTokenInformation( | |
IntPtr TokenHandle, | |
int TokenInformationClass, | |
IntPtr TokenInformation, | |
uint TokenInformationLength, | |
out uint ReturnLength);' | |
$type = Add-Type -MemberDefinition $sig -name 'gettokeninfo' -namespace 'psutils.sudo.diag' -passthru | |
$tok_elevation_type = 18 | |
$tokenInfLength = [runtime.interopservices.marshal]::SizeOf([int]) | |
$tokenInformation = [runtime.interopservices.marshal]::AllocHGlobal($tokenInfLength) | |
$res = $type::GetTokenInformation($id.Token, $tok_elevation_type, $tokenInformation, $tokenInfLength, [ref]$tokenInfLength) | |
if(!$res) { 'sudo: couldn''t get token information' } | |
else { | |
$eltype = [runtime.interopservices.marshal]::ReadInt32($tokenInformation) | |
"elevation type: $eltype" | |
} | |
# operating system | |
$os = gwmi Win32_OperatingSystem | |
"OS name: $($os.name)" | |
"OS version: $($os.version)" | |
"OS architecture: $($os.osarchitecture)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment