Exploring Group Membership

by Oct 2, 2012

To find out the groups your account belongs to, there is a command line tool called whoami. This tool supports options to output the information as comma-separated values. PowerShell can pick up CSV data and convert it to real objects. So with one simple line, you turn whoami in a valuable graphical tool:

PS> whoami /groups /fo CSV | ConvertFrom-Csv | Out-GridView

Since the data returned from whoami is turned into objects, it is now easy to derive functions, for example to test whether or not a user is a local administrator:

function Test-LocalAdmin { 
(whoami /groups /fo CSV | ConvertFrom-Csv | where { $_.SID -eq 'S-1-5-32-544' }) -ne $null
}

Twitter This Tip! ReTweet this Tip!