CRIIT
asked on
How to query the local account's group name in VBScript?
Hi,
I have this script attached as below, it queries the local accounts on the computer. But how do you find out what group the account belongs to, using the script? For an example, the local account "MyPC1\Administrator" is a member of the "Administrators" group. This script doesn't tell the group information. So, can anyone help?
thanks a lot in advance.
I have this script attached as below, it queries the local accounts on the computer. But how do you find out what group the account belongs to, using the script? For an example, the local account "MyPC1\Administrator" is a member of the "Administrators" group. This script doesn't tell the group information. So, can anyone help?
thanks a lot in advance.
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_UserAccount Where LocalAccount = True")
For Each objItem in colItems
Wscript.Echo "Account Type: " & objItem.AccountType
Wscript.Echo "Caption: " & objItem.Caption
Wscript.Echo "Description: " & objItem.Description
Wscript.Echo "Disabled: " & objItem.Disabled
Wscript.Echo "Domain: " & objItem.Domain
Wscript.Echo "Full Name: " & objItem.FullName
Wscript.Echo "Local Account: " & objItem.LocalAccount
Wscript.Echo "Lockout: " & objItem.Lockout
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "Password Changeable: " & objItem.PasswordChangeable
Wscript.Echo "Password Expires: " & objItem.PasswordExpires
Wscript.Echo "Password Required: " & objItem.PasswordRequired
Wscript.Echo "SID: " & objItem.SID
Wscript.Echo "SID Type: " & objItem.SIDType
Wscript.Echo "Status: " & objItem.Status
Wscript.Echo
Next
ASKER
i will try tomorrow, and let u know, thanks
On Error Resume Next
Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D
Set objOU = GetObject _
("LDAP://cn=Users,dc=NA,dc =fabrikam, dc=com")
ObjOU.Filter= Array("user")
For Each objUser in objOU
WScript.Echo objUser.cn & " is a member of: "
WScript.Echo vbTab & "Primary Group ID: " & _
objUser.Get("primaryGroupI D")
arrMemberOf = objUser.GetEx("memberOf")
If Err.Number <> E_ADS_PROPERTY_NOT_FOUND Then
For Each Group in arrMemberOf
WScript.Echo vbTab & Group
Next
Else
WScript.Echo vbTab & "memberOf attribute is not set"
Err.Clear
End If
Wscript.Echo
Next
Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D
Set objOU = GetObject _
("LDAP://cn=Users,dc=NA,dc
ObjOU.Filter= Array("user")
For Each objUser in objOU
WScript.Echo objUser.cn & " is a member of: "
WScript.Echo vbTab & "Primary Group ID: " & _
objUser.Get("primaryGroupI
arrMemberOf = objUser.GetEx("memberOf")
If Err.Number <> E_ADS_PROPERTY_NOT_FOUND Then
For Each Group in arrMemberOf
WScript.Echo vbTab & Group
Next
Else
WScript.Echo vbTab & "memberOf attribute is not set"
Err.Clear
End If
Wscript.Echo
Next
ASKER
Hi MeCanHelp, I was looking to query the local account, not the domain account. thanks
ASKER
Hi asawatzki:
I tried your script. It runs without any error. but it displays all the group names from the local computer, but didn't display the particular group that one account belongs to. any idea? thanks
I tried your script. It runs without any error. but it displays all the group names from the local computer, but didn't display the particular group that one account belongs to. any idea? thanks
ASKER
also, what is that "Function WMIDateStringToDate(dtmDat e)" for? thanks
You can toss that Function. It converts WMI dates to string format. Not being used in this script. The account in question, is it a local user? Also is the group that you are looking to see the user in, is it a local group?
Thanks
Thanks
ASKER
yeah, i am trying to query the local accounts to see what local groups each account belongs to. For an example:
My computer name: PC1
One of the local accounts: test1
test1 belongs to "Backup Operators" and this is the only group that test1 belongs.
but when i run your script, it displays all the group names
any comment? thanks
My computer name: PC1
One of the local accounts: test1
test1 belongs to "Backup Operators" and this is the only group that test1 belongs.
but when i run your script, it displays all the group names
any comment? thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
great, it works, thanks a lot
Open in new window