Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Active Directory Last logon time script help

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Active Directory Last logon time script help
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 Active Directory Last logon time script help - 12/11/2006 11:21:38 PM   
  mcam9

 

Posts: 25
Score: 0
Joined: 10/12/2006
Status: offline
i have a script that at the moment checks to see if a user is disabled in active directory


      

im not too sure how too incorporate querying the last logon time of the user into this script, any help would be greatly appreciated
 
 
Post #: 1
 
 RE: Active Directory Last logon time script help - 12/12/2006 3:05:56 AM   
  ginolard


Posts: 1082
Score: 21
Joined: 8/10/2005
Status: offline
Depends.

Are you in a native Windows2003 domain?

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to mcam9)
 
 
Post #: 2
 
 RE: Active Directory Last logon time script help - 12/13/2006 4:16:54 PM   
  dm_4ever


Posts: 2721
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
If you wanted the last logon time you would need to modify your command text to retrieve the lastlogon and then use a function to change it into a date/time format. I currently can't try it to see if it works, but you would use something like this:
NOTE: You will be getting the lastlogon time stamp for the user on the server you happen to query. You would need to create a new sub or seperate script to gather the lastlogon time stamp for a user on all servers to have a reliable lastlogon time.

objCommand.CommandText = _
  "<GC://ad.test.com>;(&(objectCategory=person)(objectClass=user)" _
&"(userPrincipalName=" &strSearchString& ")"_
&"(userAccountControl:1.2.840.113556.1.4.803:=2));userPrincipalName,lastlogon;subtree"
Set objRecordSet = objCommand.Execute
'Wscript.Echo "record count =" & objRecordset.RecordCount
If objRecordset.RecordCount > 0 Then ' if UPN & disabled mask were matched together during query
'Produce output based on results : modify from here on to produce different input for updated DB vbs script
   WScript.Echo "Last Logon Time: " &  GetLast(objRecordSet("lastlogon").Value)
   objTextFile.WriteLine strUserNameForOutput &"," & strUserDomainForOutput ' UPN found as disabled
End If

Function getLast(last)
   getLast = ((last.HighPart * (2^32) + last.LowPart) / (60 * 10000000) / 1440) + #1/1/1601#
End Function

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to mcam9)
 
 
Post #: 3
 
 RE: Active Directory Last logon time script help - 12/13/2006 11:14:17 PM   
  mcam9

 

Posts: 25
Score: 0
Joined: 10/12/2006
Status: offline
quote:

ORIGINAL: dm_4ever

If you wanted the last logon time you would need to modify your command text to retrieve the lastlogon and then use a function to change it into a date/time format. I currently can't try it to see if it works, but you would use something like this:
NOTE: You will be getting the lastlogon time stamp for the user on the server you happen to query. You would need to create a new sub or seperate script to gather the lastlogon time stamp for a user on all servers to have a reliable lastlogon time.

objCommand.CommandText = _
"<GC://ad.test.com>;(&(objectCategory=person)(objectClass=user)" _
&"(userPrincipalName=" &strSearchString& ")"_
&"(userAccountControl:1.2.840.113556.1.4.803:=2));userPrincipalName,lastlogon;subtree"
Set objRecordSet = objCommand.Execute
'Wscript.Echo "record count =" & objRecordset.RecordCount
If objRecordset.RecordCount > 0 Then ' if UPN & disabled mask were matched together during query
'Produce output based on results : modify from here on to produce different input for updated DB vbs script
  WScript.Echo "Last Logon Time: " &  GetLast(objRecordSet("lastlogon").Value)
  objTextFile.WriteLine strUserNameForOutput &"," & strUserDomainForOutput ' UPN found as disabled
End If

Function getLast(last)
   getLast = ((last.HighPart * (2^32) + last.LowPart) / (60 * 10000000) / 1440) + #1/1/1601#
End Function


im getting a syntax error for this line in red above, i cant for the life of me see what it is

(in reply to dm_4ever)
 
 
Post #: 4
 
 RE: Active Directory Last logon time script help - 12/14/2006 1:16:48 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
Is that your entire code?

_____________________________

"... 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 mcam9)
 
 
Post #: 5
 
 RE: Active Directory Last logon time script help - 12/14/2006 1:23:54 AM   
  mcam9

 

Posts: 25
Score: 0
Joined: 10/12/2006
Status: offline
no, this is it here


      

(in reply to ebgreen)
 
 
Post #: 6
 
 RE: Active Directory Last logon time script help - 12/14/2006 1:24:41 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
You cannot declare a function inside a loop.

_____________________________

"... 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 mcam9)
 
 
Post #: 7
 
 RE: Active Directory Last logon time script help - 12/14/2006 1:43:24 AM   
  mcam9

 

Posts: 25
Score: 0
Joined: 10/12/2006
Status: offline
cheers, no errors now, but the line   WScript.Echo "Last Logon Time: " &  GetLast(objRecordSet("lastlogon").Value)  doesnt seem to produce anything.

(in reply to ebgreen)
 
 
Post #: 8
 
 RE: Active Directory Last logon time script help - 12/14/2006 2:27:51 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
Uncomment this line:

'Wscript.Echo "record count =" & objRecordset.RecordCount

And see what the record count is.

_____________________________

"... 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 mcam9)
 
 
Post #: 9
 
 RE: Active Directory Last logon time script help - 12/14/2006 2:36:51 AM   
  mcam9

 

Posts: 25
Score: 0
Joined: 10/12/2006
Status: offline
it says the record count is 0 everytime, but that cant be right as it is writing out the names to the a csv file

(in reply to ebgreen)
 
 
Post #: 10
 
 RE: Active Directory Last logon time script help - 12/14/2006 2:50:01 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
Are you sure that it is? The file is opened for appending, so if there was data already there it would not be erased. Rename the file on your drive then run it again and see what you get.

_____________________________

"... 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 mcam9)
 
 
Post #: 11
 
 RE: Active Directory Last logon time script help - 12/14/2006 3:01:30 AM   
  mcam9

 

Posts: 25
Score: 0
Joined: 10/12/2006
Status: offline
when i change the file name it just says file not found.

(in reply to ebgreen)
 
 
Post #: 12
 
 RE: Active Directory Last logon time script help - 12/14/2006 3:04:18 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
Sorry, I should have been more explicit. You need to also create an empty file with the old file name. 

_____________________________

"... 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 mcam9)
 
 
Post #: 13
 
 RE: Active Directory Last logon time script help - 12/14/2006 3:16:08 AM   
  mcam9

 

Posts: 25
Score: 0
Joined: 10/12/2006
Status: offline
i done that and nothing happens at all

(in reply to ebgreen)
 
 
Post #: 14
 
 RE: Active Directory Last logon time script help - 12/14/2006 3:21:39 AM   
  dm_4ever


Posts: 2721
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
I don't see where you assing a value to strSearchString when querying AD.

< Message edited by dm_4ever -- 12/14/2006 3:29:31 AM >


_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to mcam9)
 
 
Post #: 15
 
 RE: Active Directory Last logon time script help - 12/14/2006 3:27:47 AM   
  mcam9

 

Posts: 25
Score: 0
Joined: 10/12/2006
Status: offline
strSearchString = strUserName & "@" & strUserDomain & ".ad.test.com"
 
its there, taking the domain and the username from the text file

(in reply to dm_4ever)
 
 
Post #: 16
 
 RE: Active Directory Last logon time script help - 12/14/2006 3:36:13 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
So the record count really is 0 and you really aren't getting any information. You need to figure out why your query isn't returning anything.

_____________________________

"... 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 mcam9)
 
 
Post #: 17
 
 RE: Active Directory Last logon time script help - 12/14/2006 3:41:57 AM   
  dm_4ever


Posts: 2721
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
I just copied the last bit of code you posted and do not see it declared in there. I did a search for strSearchString and can't find it.

Take the AD piece into a seperate vbs and try querying one user to see if you are getting the data you want. I just tried the following which is similar to what you have.


      

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to mcam9)
 
 
Post #: 18
 
 RE: Active Directory Last logon time script help - 12/14/2006 3:43:06 AM   
  mcam9

 

Posts: 25
Score: 0
Joined: 10/12/2006
Status: offline
but the condition  If objRecordset.RecordCount > 0  is being met as the wscript.echo's are coming out, and these would only come out if the condition is met. to say im confused is an understatement

(in reply to ebgreen)
 
 
Post #: 19
 
 RE: Active Directory Last logon time script help - 12/14/2006 3:44:43 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
quote:

cheers, no errors now, but the line   WScript.Echo "Last Logon Time: " &  GetLast(objRecordSet("lastlogon").Value)  doesnt seem to produce anything.


quote:

the wscript.echo's are coming out



These two statements are contradictory. Are the echos producing output or not?

_____________________________

"... 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 mcam9)
 
 
Post #: 20
 
 
Page:   [1] 2   next >   >>
 
  

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 >> Active Directory Last logon time script help Page: [1] 2   next >   >>
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