Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Script export users in AD

2 views
Skip to first unread message

Jerold Schulman

unread,
Feb 24, 2006, 7:40:48 AM2/24/06
to
On Fri, 24 Feb 2006 03:09:26 -0800, "Baba" <Ba...@discussions.microsoft.com> wrote:

>Hi.
>I have a domain with several OUs.
>I need a script to export in excel the users of all OUs.
>any idea? :(

Here is a begriming:

On Error Resume Next
Dim objConnection, objCommand, objRootDSE, strDNSDomain
Dim strFilter, strQuery, objRecordSet
dim fso, contents, writefile
set fso = CreateObject("Scripting.FileSystemObject")
set writefile = fso.CreateTextFile("C:\TEMP\SortADU.tm1", 2)
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOOBject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"
strFilter = "(&(objectCategory=person)(objectClass=user))"
strAttributes = "distinguishedName"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 99999
objCommand.Properties("Timeout") = 300
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strDN = objRecordSet.Fields("distinguishedName")
ouPath = Split(strDN, ",")
ouLen = Len(ouPath(1))
ouNameLen = ouLen - 3
ouc = Left (ouPath(1), 3)
oun = Right(ouPath(1), ouNameLen)
contents = """" & ouc & oun & """;""" & strDN & """"
writefile.writeLine contents
objRecordSet.MoveNext
Loop
objConnection.Close
writefile.close
Set objConnection = Nothing
Set objCommand = Nothing
Set objRootDSE = Nothing
Set objRecordSet = Nothing

I would sort the "C:\TEMP\SortADU.tm1" file
and create a csv of the output.


Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com
http://www.jsifaq.com

Baba

unread,
Feb 24, 2006, 8:55:26 AM2/24/06
to
My antivirus says that this script is a trojan,
Trojan-Dropper.VBS.Bomgen.h........................
--
Admin of Wellage Community
http://www.wellage.net

Jerold Schulman

unread,
Feb 24, 2006, 9:20:46 AM2/24/06
to
On Fri, 24 Feb 2006 05:55:26 -0800, "Baba" <Ba...@discussions.microsoft.com> wrote:

>My antivirus says that this script is a trojan,
>Trojan-Dropper.VBS.Bomgen.h........................

Your anti-virus is sadly mistaken.
Just looking at it you can see that it isn't.

0 new messages