Skip to content

Commit

Permalink
Use @AnthonyMastrean's is_admin from issue #5
Browse files Browse the repository at this point in the history
  • Loading branch information
lukesampson committed Feb 25, 2014
1 parent 32355ba commit cd692be
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions sudo.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
if(!$args) { "usage: sudo <cmd...>"; exit 1 }

function is_admin {
$id = [security.principal.windowsidentity]::getcurrent()
$name = $id.name -replace '^[^\\]*\\', ''
$admin_group = (gwmi win32_group -filter "LocalAccount=True AND SID='S-1-5-32-544'").name # be language-agnostic
$res = gwmi win32_groupuser | ? { $_.groupcomponent -match "name=`"$admin_group`"" -and $_.partcomponent -match "name=`"$name`"" }
$res = net localgroup administrators |? { $_ -match $env:username }
if($res) { $true }
}

Expand Down

0 comments on commit cd692be

Please sign in to comment.