Login | |
|
 |
Simple script to show all users error - 6/15/2006 1:32:46 AM
|
|
 |
|
| |
cbueno
Posts: 2
Score: 0
Joined: 6/15/2006
Status: offline
|
Hi all The following code is code for listing all the users within active directory. It seems to give me an error in line 14 where" Set colItems = GetObject("LDAP://" & strUserDN)" .It doesnt say anything just says error and puts the pointer at the start of the line. Does anyone help me identify what maybe the problem please? Regards CB ------------------------------------------------------------------------------------------------------ Option Explicit Dim colItems, objUser, strUserDN, objShell, lngBiasKey, lngBias, k Dim objRootDSE, strDNSDomain, objDomain, objMaxPwdAge, intMaxPwdAge Dim objDate, dtmPwdLastSet, lngFlag, blnPwdExpire, blnExpired Dim lngHighAge, lngLowAge, myExcel, myWrkb, myExcelPath Set myExcel = CreateObject("Excel.Application") Set myWrkb = myExcel.Workbooks.Add() myExcelPath = "C:\me.xls" ' Hard code user Distinguished Name. strUserDN = "OU=DMWMigratedUsers,OU=DMWCreatedObjects,DC=mycomp,DC=com" Set colItems = GetObject("LDAP://" & strUserDN) ' Obtain local time zone bias from machine registry. Set objShell = CreateObject("Wscript.Shell") lngBiasKey = objShell.RegRead("HKLM\System\CurrentControlSet\Control\" _ & "TimeZoneInformation\ActiveTimeBias") If UCase(TypeName(lngBiasKey)) = "LONG" Then lngBias = lngBiasKey ElseIf UCase(TypeName(lngBiasKey)) = "VARIANT()" Then lngBias = 0 For k = 0 To UBound(lngBiasKey) lngBias = lngBias + (lngBiasKey(k) * 256^k) Next End If colItems.Filter = Array( "User" ) For each objUser in colItems WScript.Echo "Name: " & objUser.Name WScript.Echo "Fullname: " & objUser.Fullname WScript.Echo "PWD last set: " & objUser.PwdLastSet Set objDate = objUser.PwdLastSet dtmPwdLastSet = Integer8Date(objDate, lngBias) ' Display password information. Wscript.Echo "User: " & strUserDN & vbCrLf & "Password last set: " & dtmPwdLastSet & "" intCounter = intCounter +1 myExcel.Cells(intCounter , 1).Value = objUser.Name myExcel.Cells(intCounter , 2).Value = objUser.Fullname myExcel.Cells(intCounter , 3).Value = objUser.PwdLastSet Next myWrkb.SaveAs (myExcelPath) myExcel.Quit Set myExcel = Nothing Set myWrkb = Nothing Set mySheet = Nothing msgbox "Last user read is " & objUser.Name ' Clean up. Set objUser = Nothing Set objShell = Nothing Set objRootDSE = Nothing Set objDomain = Nothing Set objMaxPwdAge = Nothing Set objDate = Nothing Function Integer8Date(objDate, lngBias) ' Function to convert Integer8 (64-bit) value to a date, adjusted for ' local time zone bias. Dim lngAdjust, lngDate, lngHigh, lngLow lngAdjust = lngBias lngHigh = objDate.HighPart lngLow = objdate.LowPart ' Account for bug in IADslargeInteger property methods. If lngLow < 0 Then lngHigh = lngHigh + 1 End If If (lngHigh = 0) And (lngLow = 0) Then lngAdjust = 0 End If lngDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) _ + lngLow) / 600000000 - lngAdjust) / 1440 Integer8Date = CDate(lngDate) End Function --------------------------------------------------------------
|
|
| |
|
|
|
 |
RE: Simple script to show all users error - 6/15/2006 1:59:41 AM
|
|
 |
|
| |
ebgreen
Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
|
If you put just this into a vbscript file by itself and run it do you get an error? Set colItems = GetObject("LDAP://OU=DMWMigratedUsers,OU=DMWCreatedObjects,DC=mycomp,DC=com")
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Simple script to show all users error - 6/15/2006 2:29:35 AM
|
|
 |
|
| |
ebgreen
Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
|
I've stated many times that I am far from being strong with AD. Unfortunately I haven't had a chance to change that despite my desire to do so. I would say that the most likely culprit is the domain string that you are using but I am not versed enough to tell you immediately how to troubleshoot such a problem. With luck someone that does know AD scripting well will wander along soon.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Simple script to show all users error - 6/15/2006 2:33:44 AM
|
|
 |
|
| |
ebgreen
Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
|
Does this script work for you? ' ------ SCRIPT CONFIGURATION ------ strDomainDN = "OU=DMWMigratedUsers,OU=DMWCreatedObjects,DC=mycomp,DC=com" ' ------ END CONFIGURATION --------- strBase = "<LDAP://" & strDomainDN & ">;" ' To search the whole forest using the global catalog, uncomment the following line: ' strBase = "<GC://" & strDomainDN & ">;" strFilter = "(&(objectclass=user)(objectcategory=person));" strAttrs = "name;" strScope = "subtree" set objConn = CreateObject("ADODB.Connection") objConn.Provider = "ADsDSOObject" objConn.Open "Active Directory Provider" set objRS = objConn.Execute(strBase & strFilter & strAttrs & strScope) objRS.MoveFirst while Not objRS.EOF WScript.Echo objRS("Name") objRS.MoveNext Wend
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|