Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Simple script to show all users error

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Simple script to show all users error
  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 >>
 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
--------------------------------------------------------------
 
 
Post #: 1
 
 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

(in reply to cbueno)
 
 
Post #: 2
 
 RE: Simple script to show all users error - 6/15/2006 2:20:18 AM   
  cbueno

 

Posts: 2
Score: 0
Joined: 6/15/2006
Status: offline
Hi
Yes it gives me thee same error. I have checked this seems to be right!  I am a beginer on this so i was wondering maybe it has to be with the way i am executing it? I placeit on the C drive and double click it!
Under OU=DMWMigratedUsers there are a number of users CNs and other OUs. Dont know what other details to give you?
Regards
CB

(in reply to ebgreen)
 
 
Post #: 3
 
 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

(in reply to cbueno)
 
 
Post #: 4
 
 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

(in reply to ebgreen)
 
 
Post #: 5
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Simple script to show all users error 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 My Own Thread
 Rate Posts