Getting SID from win32_groupuser

2

I am trying to get the SIDs of users and groups by querying

get-wmiobject -query 'select groupcomponent,partcomponent from win32_groupuser`

output:

__GENUS          : 2
__CLASS          : Win32_GroupUser
__SUPERCLASS     :
__DYNASTY        :
__RELPATH        : Win32_GroupUser.GroupComponent="\\\\COMPUTER\\root\\cimv2:Win32_Group.Domain=\"TESTDOMAIN\",Name=\
                   "Schema Admins\"",PartComponent="\\\\COMPUTER\\root\\cimv2:Win32_UserAccount.Domain=\"TESTDOMAIN\"
                   ,Name=\"Administrator\""
__PROPERTY_COUNT : 2
__DERIVATION     : {}
__SERVER         :
__NAMESPACE      :
__PATH           :
GroupComponent   : \\COMPUTER\root\cimv2:Win32_Group.Domain="TESTDOMAIN",Name="Schema Admins"
PartComponent    : \\COMPUTER\root\cimv2:Win32_UserAccount.Domain="TESTDOMAIN",Name="Administrator"

groupcomponent is a win32_group (https://msdn.microsoft.com/en-us/library/windows/desktop/aa394153%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396).

win32_group is contains an SID (https://msdn.microsoft.com/en-us/library/windows/desktop/aa394151%28v=vs.85%29.aspx#)

However the groupcomponent here is a string and not a win32_group as

get-wmiobject -query 'select groupcomponent.sid from win32_groupuser'

is an invalid query. How can I access groupcomponent's members as a win32_group?

A G

Posted 2016-04-27T15:44:48.037

Reputation: 463

Answers

1

The PartComponent Property contains the SID. Access it by iterating through all objects via WMI:

gwmi win32_groupuser | % { [wmi]$_.partcomponent }

or use

gwmi win32_groupuser | % { [wmi]$_.partcomponent | select SID } 

to only receive the SID.

SimonS

Posted 2016-04-27T15:44:48.037

Reputation: 4 566

How would I use this from vbscript? I'm currently using a query so I can do objWMIService.ExecQuery("select partcomponent,groupcomponent from win32_groupuser"), however that doesn't work with the commands above. – A G – 2016-04-28T10:06:27.653

@AG hmm i'm not quite sure about VB, and I never wrote a VB-Script. Always using PowerShell. You should ask this in a new question, and accept this as an answer, since your original question has been answered. – SimonS – 2016-04-28T11:31:29.133