distinguish between local or domain account?

C

Chris Sharp

The script below obtains the groups and their users on the local machine
(both local and domain accounts), but I'm trying to figure out how to
determine whether they are local or domain users. This has to run
effectively in a situation where the computer is joined to the Domain, but
the current logged-in user has logged in to the local machine.
I tried adding a '.domain' to the objGroup but it is not recognized. Thanks
much for any help.

-CPSharp

strComputer = "."
Set colGroups = GetObject("WinNT://" & strComputer & "")
colGroups.Filter = Array("group")
For Each objGroup In colGroups
Wscript.Echo objGroup.Name
For Each objUser in objGroup.Members
Wscript.Echo vbTab & objUser.Name
Next
Next
 
T

Torgeir Bakken \(MVP\)

Chris said:
The script below obtains the groups and their users on the local machine
(both local and domain accounts), but I'm trying to figure out how to
determine whether they are local or domain users. This has to run
effectively in a situation where the computer is joined to the Domain, but
the current logged-in user has logged in to the local machine.
I tried adding a '.domain' to the objGroup but it is not recognized. Thanks
much for any help.
(snip)
Hi

Note that for the WinNT provider, your script will run faster if you
use the actual computer name instead of "." (use the WScript.Network
object to obtain the computer name, see example below).

To determine if the user is a domain user or not, you need to parse
the ADsPath property of the user. Here is a script that will return
only local users as well as "NT AUTHORITY" builtin accounts (e.g.
"Authenticated Users", "INTERACTIVE" etc.):


Set objWshNet = CreateObject("WScript.Network")
strComputer = objWshNet.ComputerName

Set colGroups = GetObject("WinNT://" & strComputer & "")
colGroups.Filter = Array("group")
For Each objGroup In colGroups
Wscript.Echo objGroup.Name
For Each objUser in objGroup.Members
If InStr(1, objUser.ADsPath, "/NT AUTHORITY/", vbTextCompare) > 0 Then
Wscript.Echo vbTab & objUser.Name & " ADsPath: " & objUser.ADsPath
Elseif InStr(1, objUser.ADsPath, "/" & strComputer & "/", vbTextCompare) _
Wscript.Echo vbTab & objUser.Name & " ADsPath: " & objUser.ADsPath
End If
Next
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top