Re: finding group user belongs too

Tech-Archive recommends: Fix windows errors by optimizing your registry



Thank you all for your input, have tried all the scripts, and would like to
know if its possible to have the ability to find out the groups all the
users are in and not the single user. In other words be able to run the
script to filter all users in AD that are in a particular group.

"Ian" <ian@xxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:tcr872lhinb89lhim0vi70daq17je86rbs@xxxxxxxxxx
I did this before I retired. Here is the source. YOU MUST CHANGE THE DC TO
BE THAT OF YOU DOMAIN

It prodices a text file that is opened in notepad, then deleted. So when
you close notepad there are NO DROPPINGS

Ian

' *****************************************************************
' Ver 1.0.0.1 by Ian Masters 11-Jan-2005
' *****************************************************************
'
On Error Resume Next

'*******************************************************
Set rootDSE=GetObject("LDAP://RootDSE";)
domainContainer = rootDSE.Get("defaultNamingContext")
'*******************************************************

strUser = InputBox("What is the users logon ID? ","USERS GROUP
MEMBERSHIPS","LoginName",1,1)

Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
'
replace monkey & com for your domain.
objCommand.CommandText = "SELECT distinguishedName FROM
'LDAP://dc=monkey,dc=com' WHERE objectCategory='user' " & "AND
sAMAccountName='"&struser &"'"
'objCommand.CommandText = "SELECT distinguishedName FROM 'LDAP://";
&domainContainer &"' WHERE objectCategory='user' " & "AND
sAMAccountName='"&struser &"'"

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strUserDN = objRecordSet.Fields("distinguishedName").Value
objRecordSet.MoveNext
Loop

Dim wsh_net, strFirstName, strLastName, strUsername
Set Wsh_net = WScript.CreateObject("WScript.Network")
strusername = wsh_net.Username
strFilePath = "C:\DOCUMENTS AND SETTINGS\" &strUsername &"\Local
Settings\Temp\"&struser &".txt"

Set FsoObject = CreateObject("Scripting.FileSystemObject") ' setup file
for output to go to
Set DataFile = FsoObject.OpenTextFile (strFilePath,2,"True")
Set wshshl = WScript.CreateObject("wscript.Shell") ' create the ouput file

set objUser = GetObject("LDAP://"; & strUserDN)
strGivenName = objUser.Get("givenName")
strSN = objUser.Get("sn")
DataFile.WriteLine "Group membership for " & strGivenName &" " & strSN
'&" -oOo- " & objUser.Get("cn")
DataFile.Writeline ""
strSpaces = ""
set dicSeenGroup = CreateObject("Scripting.Dictionary")
DisplayGroups "LDAP://"; & strUserDN, strSpaces, dicSeenGroup

DataFile.close() ' close ouput file
wshShl.run "Notepad " &strFilePath ' Open ouput file in Notepad
Wscript.sleep(500) ' pause ½second
Set fso = CreateObject("Scripting.FileSystemObject") ' setup output file
for deletion
Set aFile = fso.GetFile(strFilePath) ' Setup file for deletion
aFile.Delete ' now delete the output file. Leaves no droppings


Function DisplayGroups ( strObjectADsPath, strSpaces, dicSeenGroup)

set objObject = GetObject(strObjectADsPath)
DataFile.WriteLine "" & strSpaces & objObject.Name
on error resume next ' Doing this to avoid an error when memberOf is
empty
if IsArray( objObject.Get("memberOf") ) then
colGroups = objObject.Get("memberOf")
Else
colGroups = Array( objObject.Get("memberOf") )
end If

for each strGroupDN In colGroups
if Not dicSeenGroup.Exists(strGroupDN) then
dicSeenGroup.Add strGroupDN, 1
DisplayGroups "LDAP://"; & strGroupDN, strSpaces & " ",
dicSeenGroup
end If
Next

End Function






On Tue, 23 May 2006 10:27:58 +0100, "AP" <ap_at_email.com> wrote:

Hi all,

I have been trying to find a vbscript that I can use to query active
directory and find out what security group each user belongs too and
write
these to a text file. Reason been is I like to find out what users are
not
in any security group at all and add them to a group.

Have tried trolling through google last few month and found nothing that
does what i want to achieve.

Anyone come a cross a way todo this?

Have rtied so many and, but no luck, including one shown on ms site

http://www.microsoft.com/technet/technetmag/issues/2006/03/ScriptingGuy/def
ault.aspx






.



Relevant Pages

  • Re: finding group user belongs too
    ... Dim wsh_net, strFirstName, strLastName, strUsername ... aFile.Delete ' now delete the output file. ... Function DisplayGroups (strObjectADsPath, strSpaces, dicSeenGroup) ... colGroups = Array) ...
    (microsoft.public.scripting.vbscript)
  • Re: Script to create huge sample files
    ... Say I have scripts that dumps some contents on to an output file handler ... With such scripts I have noticed 2 types of behaviour. ... to do with output buffer. ... Shlomi Fish http://www.shlomifish.org/ ...
    (perl.beginners)
  • How do I redirect output to a file and to the console screen?
    ... I'm doing some TELNET and FTP sessions with my scripts. ... redirect all the output to an output file, ...
    (comp.lang.python)
  • Re: DCL script for a dummy like me ...
    ... > I'm trying to do my first DCL scripts but I'm in trouble. ... > output file. ... You will want to look at the lexicals: ... $OPEN/WRITE logfile MYLOGFILE.TXT ...
    (comp.os.vms)
  • Newbie question
    ... I'm very new at wmi and I was just browsing to some scripts when I stumbled ... For Each objGroup In colGroups ...
    (microsoft.public.win32.programmer.wmi)