Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Export AD Information to MS Access, (computers, users, and Group Memberships)

 
Logged in as: Guest
arrSession:exec spGetSession 2,16,34962
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> Export AD Information to MS Access, (computers, users, and Group Memberships)
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Export AD Information to MS Access, (computers, users, ... - 5/30/2006 4:53:31 AM   
  edavis6678

 

Posts: 122
Score: 0
Joined: 1/12/2006
Status: offline
Reposting the script here.

This script will export all group memberships, (including primary group information), to an MS Access Table.

2 Variables you will need to change.

Line 10 : Location of your MS Access Database
Line 11:  WinNT Domain Name

This script will also create the appropriate table, (you can change the table name on Line 14 if you like)

This also includes the AD Group Description.


      

< Message edited by edavis6678 -- 5/30/2006 5:13:40 AM >
 
 
Revisions: 2 | Post #: 1
 
 RE: export ad user's group memberships to MS Access - 5/30/2006 5:09:40 AM   
  edavis6678

 

Posts: 122
Score: 0
Joined: 1/12/2006
Status: offline
This script export ALL AD Users in Active Directory and writes the user properties to MS Access Database.

Change Line 10 to the location of your MS Access Database.  (can be blank database, the script auto-creates the table and when re-run, deletes old value and re-populates)


      

< Message edited by edavis6678 -- 5/31/2006 2:22:15 AM >

(in reply to edavis6678)
 
 
Revisions: 1 | Post #: 2
 
 RE: export ad user's group memberships to MS Access - 5/30/2006 5:13:05 AM   
  edavis6678

 

Posts: 122
Score: 0
Joined: 1/12/2006
Status: offline
Exports all Computer Accounts from AD to MS Access.  Includes computers "password age" in days.  (this can give you an indication of when the last time a computer has "checked" in with AD.

Change line 7 to your MS Access Location
Change line 8 to your Domain Name


      

< Message edited by edavis6678 -- 5/31/2006 2:22:03 AM >

(in reply to edavis6678)
 
 
Revisions: 1 | Post #: 3
 
 RE: export ad user's group memberships to MS Access - 5/30/2006 6:36:27 PM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
Just in case people ask why they dont work. here is the problem

Set objRoot = GetObject("[link=http://www.visualbasicscript.com/ldap://RootDSE]LDAP://RootDSE[/link
should read
Set objRoot = GetObject("LDAP://RootDSE")

(in reply to edavis6678)
 
 
Revisions: 2 | Post #: 4
 
 RE: export ad user's group memberships to MS Access - 5/31/2006 2:22:59 AM   
  edavis6678

 

Posts: 122
Score: 0
Joined: 1/12/2006
Status: offline
thanks.  Forgot about that http links that get created on RootDSE.

I edited the originals and removed the hyperlinks.

(in reply to gdewrance)
 
 
Post #: 5
 
 RE: export ad user's group memberships to MS Access - 5/31/2006 5:07:36 PM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
I was playing around so the script could find the default Domain and came up with this.(Worked for me let me know if its correct)

For your Group and Computer Scripts try adding. (AD Users script finds the default already)

Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")

then in the computer script change the line  to Set NTaccount = GetObject("WinNT://" & DomainString & "/" & ComputerName & "$")

and remove or comment out 'DomainName = "DOMAIN"
and
'strDomainName = "DOMAIN" ' change this to your domain name

I just commented it out.

< Message edited by gdewrance -- 5/31/2006 5:11:02 PM >


_____________________________

"You start coding. I'll go find out what they want."

(in reply to edavis6678)
 
 
Revisions: 1 | Post #: 6
 
 RE: Export AD Information to MS Access, (computers, use... - 6/2/2006 4:29:12 AM   
  docjay

 

Posts: 3
Score: 0
Joined: 6/2/2006
Status: offline
Hey all - I have to agree, wonderful script!   We use it to get all of the users from a global group and run it against a database webveiwer access log for a nice view of who has logged in and used our website within our domain.

Just one thing that I can't get working with it.. with the script that gets everyone that belongs to a group (the one we use - just great!) I need to add first & last name to it so that we can see not only just the username becuase they aren't very descriptive when they make those, so the first & last name helps out a lot.  If anyone could help me out by adding those fields in the script, we would really appreciate it. 

I tried messing around with it, but it just told me that those fields don't exist when I run it.  Here is what I tried to run.


      

(in reply to edavis6678)
 
 
Post #: 7
 
 RE: Export AD Information to MS Access, (computers, use... - 6/5/2006 3:48:07 AM   
  edavis6678

 

Posts: 122
Score: 0
Joined: 1/12/2006
Status: offline
Really nice to see this in action.  your problem is your table doesn't have the fields available to take data.

Just expand your table and you'll be good to go.

Line 20:

Was this:

SqlCommand = "CREATE TABLE [" & dbTableName & "] (ADGroupName Text(150), SamAccountName Text(150), Department Text(150), IsPrimary BIT, UserAdsPath Memo,ADGroupDescription Text(150))"

Change to this:

SqlCommand = "CREATE TABLE [" & dbTableName & "] (ADGroupName Text(150),FirstName Text(150), LastName Text(150), SamAccountName Text(150), Department Text(150), IsPrimary BIT, UserAdsPath Memo,ADGroupDescription Text(150))"

Hope this explains it.

-Eric

(in reply to docjay)
 
 
Revisions: 1 | Post #: 8
 
 RE: Export AD Information to MS Access, (computers, use... - 6/5/2006 4:09:59 AM   
  docjay

 

Posts: 3
Score: 0
Joined: 6/2/2006
Status: offline
well, I think that just about got it, but there is another error..

Line:  81
Char: 1
Error:  The directory property cannot be found in the cache.
code:  8000500D
Source:  Active Directory.

here is what I am running now...


      

(in reply to edavis6678)
 
 
Post #: 9
 
 RE: Export AD Information to MS Access, (computers, use... - 6/5/2006 5:43:07 AM   
  edavis6678

 

Posts: 122
Score: 0
Joined: 1/12/2006
Status: offline
That happens when a value is NOT set within Active Directory.  (probably a service account or some account with no LastName property value)

The fastest way to solve this problem, (although it could be problematic when debubggin).

Add the famous, ON ERROR RESUME NEXT as you are grabbing the values.  (add it after line 75)

Then, to put error control back on, put ON ERROR GOTO 0 (add this after line 84)

(this is the same thing I do on lines 17-20 - I did it there because if you run the script twice the table in the database will already exist,causing the script to bomb.  Kinda lazy to do it that way, but i didn't want to spend half the day writing error trapping when it's just really not necessary)

< Message edited by edavis6678 -- 6/5/2006 5:45:43 AM >

(in reply to docjay)
 
 
Revisions: 1 | Post #: 10
 
 RE: Export AD Information to MS Access, (computers, use... - 6/5/2006 7:15:54 AM   
  docjay

 

Posts: 3
Score: 0
Joined: 6/2/2006
Status: offline
okay, well the script runs now!  thank you - but the first & last name fields are blank.. is this because of how AD was built on my side?

here is what I'm running now...


      

(in reply to edavis6678)
 
 
Post #: 11
 
 RE: Export AD Information to MS Access, (computers, use... - 6/6/2006 3:39:13 AM   
  edavis6678

 

Posts: 122
Score: 0
Joined: 1/12/2006
Status: offline
The reason is 1 or more of your AD accounts doesnt' have information filled in for the First and Last Name fields.

btw...you On error resume next is wrong, below is it modified.

(also, if you want to find out what accounts have the missing property, run the script via Cscript and use wscript.echo to see which account has the missing properties.


      

(in reply to docjay)
 
 
Post #: 12
 
 RE: Export AD Information to MS Access, (computers, use... - 6/27/2006 4:40:19 AM   
  DataBase

 

Posts: 3
Score: 0
Joined: 6/27/2006
Status: offline
Worked fine for me :-)

when we will see any import script ?


Thanks allot

(in reply to edavis6678)
 
 
Post #: 13
 
 RE: Export AD Information to MS Access, (computers, use... - 2/13/2008 11:00:06 PM   
  jamiepryer

 

Posts: 4
Score: 0
Joined: 2/13/2008
Status: offline
wow - this is a quality scrip, im very impressed - thank you so much!
i never sign up to thse forums however i thought i would take the time to, because of the effort you have put in!

i did have one question also...from the first script (This script will export all group memberships, (including primary group information), to an MS Access Table) i would like to remove "department", "UserAdsPath" and also "IS Primary Bit" - however im not too sure how to do this.
Really sorry but can someone advise please....

(in reply to DataBase)
 
 
Post #: 14
 
 RE: Export AD Information to MS Access, (computers, use... - 2/14/2008 11:15:30 PM   
  jamiepryer

 

Posts: 4
Score: 0
Joined: 2/13/2008
Status: offline
also, my script keeps crashing, as it time's out or something
anyone know how to stop this or slow it down maybe, so it doesnt keep killing my pc and not completing a full export?
up 45,000 lines in access so far when it dies and there is loads more info to get

(in reply to jamiepryer)
 
 
Post #: 15
 
 RE: Export AD Information to MS Access, (computers, use... - 2/19/2008 4:22:48 AM   
  edavis6678

 

Posts: 122
Score: 0
Joined: 1/12/2006
Status: offline
Nice to see someone get some use from it.

I can answer part of your problem.

To modify the data collected, first delete the existing table and re-run the script with the following changes:

SqlCommand = "CREATE TABLE [" & dbTableName & "] (ADGroupName Text(150), SamAccountName Text(150),ADGroupDescription Text(150))"

Change the Insert command in both places:

1st Insert:

qryInsert = "INSERT INTO [" & dbTableName & "](ADGroupName, SamAccountName) VALUES ('" & ADGroupName & "','" & SamAccountName & "')"

2nd Insert:

qryInsert = "INSERT INTO [" & dbTableName & "](ADGroupName, ADGroupDescription, SamAccountName) VALUES ('" & ADGroupName & "','" & ADGroupDescription & "','" & SamAccountName & "')"


As for it dying after 45K records?  You may have to go to MS SQL or some other type of database.  Make sure your MDB is local to your machine.   Not sure what else.

Hope this helps

(in reply to jamiepryer)
 
 
Post #: 16
 
 RE: Export AD Information to MS Access, (computers, use... - 2/20/2008 10:33:26 PM   
  jamiepryer

 

Posts: 4
Score: 0
Joined: 2/13/2008
Status: offline
thanks a lot for your help, yet again!

its still eating all my cpu and i think it falls over when i dont hvae any physical memory left.
was thinking that i maybe need to add a "wscipt.sleep" into this, but not sure where?

(in reply to edavis6678)
 
 
Post #: 17
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Post a VBScript >> Export AD Information to MS Access, (computers, users, and Group Memberships) Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete