Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Get an output all all contacts that are created today.

Hi,

I regularly create contacts with a script.I need a way to get all the contacts that i have created or anyone has created to a file.
A file which will have all the contacts that are created on the run date.
These details. Need to query with the ADS.
Displayname
Firstname
Lastname
Email
Description

Regards
Sharath
Avatar of Adrian Pop
Adrian Pop
Flag of Sweden image

Avatar of RobSampson
Sharath, to use the code from the link that adrpo provided:

'=====================
On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2

dtmCreationDate1 = Left(TimeNow(Now), 8) & "000000.0Z"
dtmCreationDate2 = Left(TimeNow(Now), 8) & "115959.0Z"

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.CommandText = _
    "SELECT Name, whenCreated FROM 'LDAP://dc=fabrikam,dc=com' WHERE objectClass='user' "  & _
        "AND whenCreated>='" & dtmCreationDate1 & "' AND whenCreated<='" & dtmCreationDate2 & "'"
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst

Do Until objRecordSet.EOF
    Wscript.Echo objRecordSet.Fields("Name").Value, objRecordSet.Fields("whenCreated").Value
    objRecordSet.MoveNext
Loop

Function TimeNow(dDateTime)
      TimeNow =      Year(Now) &_
                        Right("00" & Month(Now), 2) &_
                        Right("00" & Day(Now), 2) &_
                        Right("00" & Hour(Now), 2) &_
                        Right("00" & Minute(Now), 2) &_
                        Right("00" & Second(Now), 2)
End Function
'=====================

Regards,

Rob.
Avatar of bsharath

ASKER

Rob i already tried the code but forgot to comment.When i run the script it just goes on reading but no output...

I even tried the code you gave me now but same it goes on reading "Wscript.exe" in processes
OK, I'll take out On Error Resume Next.....and make sure you change the domain DC parameters:

'=====================
Const ADS_SCOPE_SUBTREE = 2

dtmCreationDate1 = Left(TimeNow(Now), 8) & "000000.0Z"
dtmCreationDate2 = Left(TimeNow(Now), 8) & "115959.0Z"

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.CommandText = _
    "SELECT Name, whenCreated FROM 'LDAP://dc=group,dc=co,dc=uk' WHERE objectClass='user' "  & _
        "AND whenCreated>='" & dtmCreationDate1 & "' AND whenCreated<='" & dtmCreationDate2 & "'"
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst

Do Until objRecordSet.EOF
    Wscript.Echo objRecordSet.Fields("Name").Value, objRecordSet.Fields("whenCreated").Value
    objRecordSet.MoveNext
Loop

Function TimeNow(dDateTime)
      TimeNow =      Year(Now) &_
                        Right("00" & Month(Now), 2) &_
                        Right("00" & Day(Now), 2) &_
                        Right("00" & Hour(Now), 2) &_
                        Right("00" & Minute(Now), 2) &_
                        Right("00" & Second(Now), 2)
End Function
'=====================

Regards,

Rob.
I get this Rob...
---------------------------
Windows Script Host
---------------------------
Script:      C:\Get Created Contacts.vbs
Line:      21
Char:      1
Error:      Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
Code:      800A0BCD
Source:       ADODB.Recordset

---------------------------
OK  
---------------------------
Change this:

objRecordSet.MoveFirst

Do Until objRecordSet.EOF
    Wscript.Echo objRecordSet.Fields("Name").Value, objRecordSet.Fields("whenCreated").Value
    objRecordSet.MoveNext
Loop



to this:

If Not objRecordSet.EOF Then
   objRecordSet.MoveFirst

   Do Until objRecordSet.EOF
       Wscript.Echo objRecordSet.Fields("Name").Value, objRecordSet.Fields("whenCreated").Value
       objRecordSet.MoveNext
   Loop
Else
   MsgBox "No records were returned."
End If


and are you sure you've created an account today?

Regards,

Rob.
I just created a contact Rob..
In the contact > Objects i have this date as created date
11/2/2007 9:33:11 AM
Maybe it's the Time Bias, depending on what time zone you're in, if it's "plus" something, such as
+600, then use the below, if it's "minus" something, like -600, then change the Plus sign in the
dtmCreationDate1 and dtmCreationDate2 lines.

'=====================
On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2

strTimeBias = Get_CurrentTimeZone_Of_Computer(".")

dtmCreationDate1 = Left(TimeNow(Now), 8) & "000000.0+" & strTimeBias
dtmCreationDate2 = Left(TimeNow(Now), 8) & "115959.0+" & strTimeBias

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.CommandText = _
    "SELECT Name, whenCreated FROM 'LDAP://dc=fabrikam,dc=com' WHERE objectClass='user' "  & _
        "AND whenCreated>='" & dtmCreationDate1 & "' AND whenCreated<='" & dtmCreationDate2 & "'"
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst

Do Until objRecordSet.EOF
    Wscript.Echo objRecordSet.Fields("Name").Value, objRecordSet.Fields("whenCreated").Value
    objRecordSet.MoveNext
Loop

Function TimeNow(dDateTime)
      TimeNow =      Year(Now) &_
                        Right("00" & Month(Now), 2) &_
                        Right("00" & Day(Now), 2) &_
                        Right("00" & Hour(Now), 2) &_
                        Right("00" & Minute(Now), 2) &_
                        Right("00" & Second(Now), 2)
End Function

Function Get_CurrentTimeZone_Of_Computer(ByVal strComputerName)

      Dim objWMIService, colLogFiles, objLogFile, intTotal, colItems, objItem, strCurrentTimeZone
      Const wbemFlagReturnImmediately = &h10
      Const wbemFlagForwardOnly = &h20

      Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
              strComputerName & "\root\cimv2")

      Set colItems = objWMIService.ExecQuery("Select CurrentTimeZone from Win32_OperatingSystem",,48)

      On Error Resume Next
      For Each objItem in colItems
            If Err.Number = 0 Then
                  On Error GoTo 0
                  strCurrentTimeZone = objItem.CurrentTimeZone
                  Exit For
            Else
                  MsgBox "Unknown Error during Time Bias for " & strComputer & "." & vbCrLf & "Error Number: " & _
                        Err.Number & vbCrLf & "Error Description: " & Err.Description, vbOKOnly, "Unknown Error"
                  Err.Clear
                  On Error GoTo 0
                  Exit For
            End If
      Next
      On Error GoTo 0

      Get_CurrentTimeZone_Of_Computer = strCurrentTimeZone
      
End Function
'=====================

Regards,

Rob.
Rob...

 depending on what time zone you're in, if it's "plus" something, such as
+600, then use the below, if it's "minus" something, like -600, then change the Plus sign in the
dtmCreationDate1 and dtmCreationDate2 lines.


Where should i check the time zone stuff...

I just ran as it is and got no message nor output...
It's just your Regional Settings time zone.  Open your Time and Date control panel, and click the Time Zone tab.  I have GMT +10:00

Regards,

Rob.
I have GMT + 5.30

Should i change anything in the script.
No, I would think so.

OK, I'm going to get you to run this script, just to output the format of your whenCreated attribute.

Set objADSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objADSysInfo.UserName)
InputBox "Prompt", "Title", objUser.WhenCreated

Then paste that format and I'll see what we can do.

Regards,

Rob.
On the box i get this...

11/22/2001 3:40:03 PM
Wow, that's way different to what I expected....hmmmmm....I'll check it out....
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial