Skip to content

Instantly share code, notes, and snippets.

@lukesampson
Last active December 24, 2015 01:39
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 lukesampson/6725722 to your computer and use it in GitHub Desktop.
Save lukesampson/6725722 to your computer and use it in GitHub Desktop.
# 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