Advertisement

08.05.2008 at 10:04AM PDT, ID: 23622983
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

Active Directory Query user account attibutes

Asked by richrumble in VB Script, Miscellaneous Networking, JScript

Tags:

I'd like to be able to specify, via a popup box or even cli, an alternate domain and or controllers to run the script below against. The script below seems to run against the controller my account logged into, and against my user domain. I'd like to specify another GC and another Domain to run this against. I don't think it needs any special priv's, as the account I ran this query from doesn't seem to. Let me know what you think of might have questions on!
Thanks!
-richStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
Dim ObjWb
Dim ObjExcel
Dim x, zz, PasswordExpiry  
Set objRoot = GetObject("LDAP://RootDSE")
strDNC = objRoot.Get("DefaultNamingContext")
Set objDomain = GetObject("LDAP://" & strDNC) ' Bind to the top of the Domain using LDAP using RootDSE
Call ExcelSetup("Sheet1") ' Sub to make Excel Document
x = 1
Call enummembers(objDomain)
Sub enumMembers(objDomain)
PasswordExpiry = 60
On Error Resume Next
 
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
 
  objwb.Cells(x, 1).Value = objMember.Class
 
SamAccountName = ObjMember.samAccountName
EmailAddr = objMember.mail
WhenCreated = ObjMember.WhenCreated
PasswordLastChanged = Objmember.PasswordLastChanged
UserAccountControl = objMember.UserAccountControl
PassAge = DateDiff("d", PasswordLastChanged, Now)
 
If objMember.UserAccountControl = 544 Then Status = "PWExpires"
If objMember.UserAccountControl = 512 Then Status = "PWExpires"
If objMember.UserAccountControl = 514 Then Status = "AccountDisabled"
If objMember.UserAccountControl = 32 Then Status = "PWnotRequired"
If objMember.UserAccountControl = 66048 Then Status = "PWdoesnotExpire"
If objMember.UserAccountControl = 66080 Then Status = "PWdoesnotExpire"
If objMember.UserAccountControl = 66082 Then Status = "PWdoesnotExpire"
If objMember.UserAccountControl = 546 Then Status = "AccountDisabled"
If objMember.UserAccountControl = 66050 Then Status = "AccountDisabled"
 
If PassAge = 39419 Then PassAge = "Unknown"
If PassAge = 39420 Then PassAge = "Never"
 
set objLogon = objMember.Get("lastLogonTimestamp")
intLogonTime = objLogon.HighPart * (2^32) + objLogon.LowPart
intLogonTime = intLogonTime / (60 * 10000000)
intLogonTime = intLogonTime / 1440
intLogonTime = intLogonTime + #1/1/1601#
 
' Write the values to Excel, using the X counter to increment the rows.
 
objwb.Cells(x, 1).Value = SamAccountName
objwb.Cells(x, 2).Value = EmailAddr
objwb.Cells(x, 3).Value = WhenCreated
objwb.Cells(x, 4).Value = PasswordLastChanged
objwb.Cells(x, 5).Value = intLogonTime
objwb.Cells(x, 6).Value = UserAccountControl
objwb.Cells(x, 7).Value = Status
objwb.Cells(x, 8).Value = PassAge
objwb.Cells(x, 9).Value = ExpireWarning
 
' Blank out Variables in case the next object doesn't have a value for the property
SamAccountName = "-" 
EmailAddr = "-"
WhenCreated = "-"
PasswordLastChanged = "-"
 
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 = "All AD Users" ' name the sheet
objwb.Activate
objExcel.Visible = True
objwb.Cells(1, 1).Value = "SamAccountName"
objwb.Cells(1, 2).Value = "Emailaddress"
objwb.Cells(1, 3).Value = "WhenCreated"
objwb.Cells(1, 4).Value = "PaswordLastChanged"
objwb.Cells(1, 5).Value = "LastLogonTime"
objwb.Cells(1, 6).Value = "AccControl"
objwb.Cells(1, 7).Value = "Status"
objwb.Cells(1, 8).Value = "PassAge"
 
End Sub
MsgBox "Script Completed" ' show that script is complete
[+][-]08.05.2008 at 11:01AM PDT, ID: 22163372

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: VB Script, Miscellaneous Networking, JScript
Tags: ADSI, WMI, VBS, VBScript
Sign Up Now!
Solution Provided By: Shift-3
Participating Experts: 1
Solution Grade: A
 
 
[+][-]08.05.2008 at 11:07AM PDT, ID: 22163421

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628