bsharath
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
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
Description
Regards
Sharath
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.Connec tion")
Set objCommand = CreateObject("ADODB.Comman d")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnectio n = objConnection
objCommand.Properties("Pag e Size") = 1000
objCommand.Properties("Sea rchscope") = 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("whenC reated").V alue
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.
'=====================
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.Connec
Set objCommand = CreateObject("ADODB.Comman
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnectio
objCommand.Properties("Pag
objCommand.Properties("Sea
objCommand.CommandText = _
"SELECT Name, whenCreated FROM 'LDAP://dc=fabrikam,dc=com
"AND whenCreated>='" & dtmCreationDate1 & "' AND whenCreated<='" & dtmCreationDate2 & "'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo objRecordSet.Fields("Name"
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.
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
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.Connec tion")
Set objCommand = CreateObject("ADODB.Comman d")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnectio n = objConnection
objCommand.Properties("Pag e Size") = 1000
objCommand.Properties("Sea rchscope") = 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("whenC reated").V alue
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.
'=====================
Const ADS_SCOPE_SUBTREE = 2
dtmCreationDate1 = Left(TimeNow(Now), 8) & "000000.0Z"
dtmCreationDate2 = Left(TimeNow(Now), 8) & "115959.0Z"
Set objConnection = CreateObject("ADODB.Connec
Set objCommand = CreateObject("ADODB.Comman
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnectio
objCommand.Properties("Pag
objCommand.Properties("Sea
objCommand.CommandText = _
"SELECT Name, whenCreated FROM 'LDAP://dc=group,dc=co,dc=
"AND whenCreated>='" & dtmCreationDate1 & "' AND whenCreated<='" & dtmCreationDate2 & "'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo objRecordSet.Fields("Name"
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.
ASKER
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
-------------------------- -
--------------------------
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("whenC reated").V alue
objRecordSet.MoveNext
Loop
to this:
If Not objRecordSet.EOF Then
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo objRecordSet.Fields("Name" ).Value, objRecordSet.Fields("whenC reated").V alue
objRecordSet.MoveNext
Loop
Else
MsgBox "No records were returned."
End If
and are you sure you've created an account today?
Regards,
Rob.
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo objRecordSet.Fields("Name"
objRecordSet.MoveNext
Loop
to this:
If Not objRecordSet.EOF Then
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo objRecordSet.Fields("Name"
objRecordSet.MoveNext
Loop
Else
MsgBox "No records were returned."
End If
and are you sure you've created an account today?
Regards,
Rob.
ASKER
I just created a contact Rob..
In the contact > Objects i have this date as created date
11/2/2007 9:33:11 AM
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_Com puter(".")
dtmCreationDate1 = Left(TimeNow(Now), 8) & "000000.0+" & strTimeBias
dtmCreationDate2 = Left(TimeNow(Now), 8) & "115959.0+" & strTimeBias
Set objConnection = CreateObject("ADODB.Connec tion")
Set objCommand = CreateObject("ADODB.Comman d")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnectio n = objConnection
objCommand.Properties("Pag e Size") = 1000
objCommand.Properties("Sea rchscope") = 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("whenC reated").V alue
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_Com puter(ByVa l strComputerName)
Dim objWMIService, colLogFiles, objLogFile, intTotal, colItems, objItem, strCurrentTimeZone
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Set objWMIService = GetObject("winmgmts:{imper sonationLe vel=impers onate}!\\" & _
strComputerName & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("S elect 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_Com puter = strCurrentTimeZone
End Function
'=====================
Regards,
Rob.
+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_Com
dtmCreationDate1 = Left(TimeNow(Now), 8) & "000000.0+" & strTimeBias
dtmCreationDate2 = Left(TimeNow(Now), 8) & "115959.0+" & strTimeBias
Set objConnection = CreateObject("ADODB.Connec
Set objCommand = CreateObject("ADODB.Comman
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnectio
objCommand.Properties("Pag
objCommand.Properties("Sea
objCommand.CommandText = _
"SELECT Name, whenCreated FROM 'LDAP://dc=fabrikam,dc=com
"AND whenCreated>='" & dtmCreationDate1 & "' AND whenCreated<='" & dtmCreationDate2 & "'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo objRecordSet.Fields("Name"
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_Com
Dim objWMIService, colLogFiles, objLogFile, intTotal, colItems, objItem, strCurrentTimeZone
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Set objWMIService = GetObject("winmgmts:{imper
strComputerName & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("S
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_Com
End Function
'=====================
Regards,
Rob.
ASKER
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...
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.
Regards,
Rob.
ASKER
I have GMT + 5.30
Should i change anything in the script.
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.
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.
ASKER
On the box i get this...
11/22/2001 3:40:03 PM
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You could use this:
http://www.microsoft.com/technet/scriptcenter/resources/qanda/aug07/hey0802.mspx
Cheers,
za-k/