Login | |
|
 |
RE: Export Active Directory Users to Excel Worksheet - 1/12/2006 3:33:51 PM
|
|
 |
|
| |
kirrilian
Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
|
have you tried this script on an AD domain that has more than 1000 users? i have run into this problem before and know how to get around it, just wondering if yours is able to or not.
_____________________________
Have you searched here ? VBScript Fundamentals My Site
|
|
| |
|
|
|
 |
RE: Export Active Directory Users to Excel Worksheet - 5/22/2006 4:31:37 AM
|
|
 |
|
| |
kirrilian
Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
|
quote:
ORIGINAL: edavis6678 oh..neat...i just tried it..very nice. Thanks, I got most of the formatting code from the script center. I've been wanting to play with the excel object and had a little time on Friday. :) quote:
The clean-up is nice too. I've been so slammed here at work, but I still have the code, (need to post it), which adds CCMAIL. I'm also thinking of expanding the output for every AD property, and eventually also support over 1K users. (the query just has to use a different provider). Whenever you want to work on that I'd be interested in helping, although I can already see one problem. We have a custom AD schema here and a generic script that pulls all attributes might not work, so maybe pulling the schema first then enumerating all the attributes that way. quote:
Also want to add an option for computers too. (which I already have written, again not cleaned up for publishing though). (I even have another that does for local accounts - add and list, (a need that arose from creating a non-domain FTP server). I'll post that sometime too :) (I know there are many free-ware scripts already written for this, but I think it's more fun to do it yourself) Again, I'd be happy to help implement doing computers rather than users as well. Thanks for the excellent script!
_____________________________
Have you searched here ? VBScript Fundamentals My Site
|
|
| |
|
|
|
 |
RE: Export Active Directory Users to Excel Worksheet - 5/26/2006 5:26:16 AM
|
|
 |
|
| |
tcole33
Posts: 6
Score: 0
Joined: 5/26/2006
Status: offline
|
Great job on the script. I was wondering if someone could help me modify this (your initial script)..... I would like it to return all of the users group memberships instead of the ADSPath.... for example John Doe Domain User Accounting IT User Jane Doe Domain Users Internet Access Group Domain Administrator etc...... I am trying to comply with SARBOX and this script is EXACTLY what I was looking for ... only I need the group memberships listed for each user...... Any help is greatly appreciated. Here is the scirpt that you had posted and I had been modifying....... Sub enumMembers(objDomain) On Error Resume Next Dim Secondary(20) ' Variable to store the Array of 2ndary email alias's For Each objMember In objDomain ' go through the collection If ObjMember.Class = "user" Then ' if not User object, move on. x = x + 1 ' counter used to increment the cells in Excel FirstName = objMember.GivenName LastName = objMember.sn Manager = ObjMember.Manager AdsPath = Objmember.Adspath zz = 1 ' Counter for array of 2ndary email addresses For each email in ObjMember.proxyAddresses If Left (email,5) = "SMTP:" Then Primary = Mid (email,6) ' if SMTP is all caps, then it's the Primary ElseIf Left (email,5) = "smtp:" Then Secondary(zz) = Mid (email,6) ' load the list of 2ndary SMTP emails into Array. zz = zz + 1 End If Next ' Write the values to Excel, using the X counter to increment the rows. objwb.Cells(x, 1).Value = FirstName objwb.Cells(x, 2).Value = LastName objwb.Cells(x, 3).Value = Manager objwb.Cells(x, 4).Value = ADSPath ' Write out the Array for the 2ndary email addresses. For ll = 1 To 20 objwb.Cells(x,26+ll).Value = Secondary(ll) Next ' Blank out Variables in case the next object doesn't have a value for the property FirstName = "-" LastName = "-" Manager = "-" For ll = 1 To 20 Secondary(ll) = "" Next End If ' If the AD enumeration runs into an OU object, call the Sub again to itinerate If objMember.Class = "organizationalUnit" or OBjMember.Class = "container" Then enumMembers (objMember) End If Next End Sub Sub ExcelSetup(shtName) ' This sub creates an Excel worksheet and adds Column heads to the 1st row Set objExcel = CreateObject("Excel.Application") Set objwb = objExcel.Workbooks.Add Set objwb = objExcel.ActiveWorkbook.Worksheets(shtName) Objwb.Name = "Active Directory Users" ' name the sheet objwb.Activate objExcel.Visible = True objwb.Cells(1, 1).Value = "FirstName" objwb.Cells(1, 2).Value = "LastName" objwb.Cells(1, 3).Value = "Manager" objwb.Cells(1, 4).Value = "Adspath" End Sub MsgBox "Done" ' show that script is complete
|
|
| |
|
|
|
 |
RE: Export Active Directory Users to Excel Worksheet - 5/27/2006 8:03:20 AM
|
|
 |
|
| |
edavis6678
Posts: 121
Score: 0
Joined: 1/12/2006
Status: offline
|
Very nice to hear that this working for. It's nice to know that someone can find a script I find useful also useful. As for other properties, it's pretty straight forward. Below are some common properties. SamAccountName = ObjMember.samAccountName Cn = ObjMember.CN FirstName = objMember.GivenName LastName = objMember.sn initials = objMember.initials Descrip = objMember.description Office = objMember.physicalDeliveryOfficeName Telephone = objMember.telephonenumber EmailAddr = objMember.mail WebPage = objMember.wwwHomePage Addr1 = objMember.streetAddress City = objMember.l State = objMember.st ZipCode = objMember.postalCode Title = ObjMember.Title Department = objMember.Department Company = objMember.Company Manager = ObjMember.Manager Profile = objMember.profilePath LoginScript = objMember.scriptpath HomeDirectory = ObjMember.HomeDirectory HomeDrive = ObjMember.homeDrive AdsPath = Objmember.Adspath LastLogin = objMember.LastLogin Here is a link from MS on the rest of them: http://windowssdk.msdn.microsoft.com/library/default.asp?url=/library/en-us/ADSI/adsi/iadsuser.asp Remember that some values are very long and some have values that don't insert well into Access unless you tweak them. (That's why i have the FixValue function in my script). Also, some values are COLLECTIONS, (so you have to write a routine to get it out). I'm not on a domain atm, so I can't test these changes, if what I posted here doesn't work, let me know and I'll correct, but below is what you need to change. If you want to change the properties, or add more, just simply add more colummns to your database table, set variables to the user object properties, then modify the INSERT command with the additional properties. For example.... If you want to ADD another columm for Manager ADS path, modify the script this way: (RED notes new lines) First, you must add a colummn to your table and name it, ManagerADSPath. Make it a MEMO type since it will return a very long value. Next, add a variable named, ManagerADS = to the AD user object property. Shown below. (also note I purposely named it differently so you can see how the INSERT command works) ADGroupName = Mid(FixValue(objADGroup.Name),4) SamAccountName = FixValue(objMember.SamAccountName) Department = FixValue(ObjMember.Department) UserADSPath = FixValue(objMember.AdsPath) ManagerADS = FixValue(objMember.Manager) qryInsert = "INSERT INTO [" & dbTableName & "](ADGroupName, SamAccountName, Department,CN, UserAdsPath, ManagerADSPath) VALUES ('" & ADGroupName & "','" & SamAccountName & "','" & Department & "', '" & CN & "', '" & UserAdsPath & "', '" & ManagerADS & '")" conn.Execute (qryInsert) Just add more and more if you want, or change some of them with what you want. Special note. Manager for a user object only returns an ADSPath. Another thing you can do. Take the excel output from the original script and IMPORT it into Access, then join the tables VIA a key field. (like SamAccountName), and make your own report, query, etc....(you could also get the Display name of the manager, but simply buidling a query and linking ADSPATH) Hope this makes sense
< Message edited by edavis6678 -- 5/27/2006 8:16:31 AM >
|
|
| | |