Re: finding group user belongs too
- From: "AP" <ap_at_email.com>
- Date: Thu, 25 May 2006 15:53:25 +0100
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 TOBE THAT OF YOU DOMAIN
you close notepad there are NO DROPPINGS
It prodices a text file that is opened in notepad, then deleted. So when
MEMBERSHIPS","LoginName",1,1)
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
replace monkey & com for your domain.
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
'
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 &"'"
Settings\Temp\"&struser &".txt"
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
for output to go to
Set FsoObject = CreateObject("Scripting.FileSystemObject") ' setup file
Set DataFile = FsoObject.OpenTextFile (strFilePath,2,"True")'&" -oOo- " & objUser.Get("cn")
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
DataFile.Writeline ""for deletion
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
Set aFile = fso.GetFile(strFilePath) ' Setup file for deletionempty
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
if IsArray( objObject.Get("memberOf") ) thendicSeenGroup
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 & " ",
end Ifwrite
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
notthese to a text file. Reason been is I like to find out what users are
ault.aspxin 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
.
- Follow-Ups:
- Re: finding group user belongs too
- From: Ian
- Re: finding group user belongs too
- References:
- finding group user belongs too
- From: AP
- Re: finding group user belongs too
- From: Ian
- finding group user belongs too
- Prev by Date: Re: Removing default gateway
- Next by Date: Copy script
- Previous by thread: Re: finding group user belongs too
- Next by thread: Re: finding group user belongs too
- Index(es):
Relevant Pages
|