lastLogon should be returned by AD as a string though that string represents
an int8 value (i.e. 64 bit integer). It won't be displayed as a date
directly, it would need to be converted. I have posted in various locations
how to convert the value to a ctime value and then decode to a string....

Here it is again
(http://groups.google.com/groups?q=Joe+Richards++ctime+perl&hl=en&lr=&selm=O
Yge%23r0QEHA.1048%40tk2msftngp13.phx.gbl&rnum=2) 


==========
Ah and here is another post I have reused multiple times....

It gets you to ctime format which you can use various tools to convert to a 
string, I have a perl script below to do it.

    joe


I have been asked multiple times for this info in newsgroups and emails
to my joeware email and again at work yesterday so I wrote this up.
Thought I would share with the group here in case anyone cares.

---

First off the 64 bit Integer Time Values (Called Integer8) represents
the number of 100 nanosecond intervals between the time stamp and
January 1, 1601. Don't ask me why, this is just what it is, I am not
even going to attempt to explain it other than I wasn't around prior to
1969 so what happened with computers in 1601 is far outside my personal
scope of really caring. In fact I am not sure anything even existed then
because I didn't, it is up for debate.

1. Remove last 7 characters - Usually this will be all zeros but it may
be actual digits if you care to get down to 100 nanosecond accuracy, you
can figure it out.

2. Subtract off 11644473600

You are now at a value that is the number of seconds since since January
1, 1970. Again I will not explain even though I was around then. I still
wasn't at the point that I worried about time stamps on computers, I was
still flabbergasted that man had walked on the moon 6 short months
previously...

This value was targeted because there are functions out there that use
that format for time already and you can leverage them to convert to a
friendly time/date stamp such as ctime or localtime or gmtime.

So how to do this in perl??

Here is a quick perl script:

___t64.pl___
$t64=shift;
$t64=~s/(.+).{7,7}/\1/;
$t64-=11644473600;
($sec, $min, $hour, $mday, $mon, $year, $wday, $ydat,
$isdst)=localtime($t64); $mon++; $year+=1900;
print "$mon/$mday/$year - $hour:$min:$sec  DST - $isdst\n";


When you run it it will produce something like:

C:\Temp>t64 127069827243689315
9/2/2003 - 9:25:24  DST - 1


Use as you wish.

For other cool methods to play with those time fields in Perl check out
Robbie Allen's upcoming book - Active Directory Cookbook. :o)


    joe



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Hon
Shi
Sent: Monday, November 22, 2004 8:38 AM
To: [EMAIL PROTECTED]
Subject: adsi date type

I've been working with perl/adsi and have not needed to look at anything but
string data.

Can someone give me a short example to read, say, the LastLogin time in a
user object?  I was just dumping some strings in a user object and this
doesn't work for nonstring data.  I suppose this is a two step process;
discover what kind of data it is, then converting it.

Thanks

  @main::userFields = qw(CN Description userPrincipalName GUID FullName
    LoginScript sAMAccountName ADsPath HomeDirectory LastLogin);

  my $ldap;
  my $spec = "LDAP://"; . $dn;
  if (!($ldap = Win32::OLE->GetObject( "$spec"))) {
    my $oleMsg = Win32::OLE->LastError();
    my $erTxt = erMsg($0, $rev, __PACKAGE__, __FILE__, __LINE__, 'ole
message',
      qq(Failed AD "$spec".\n) .
      qq(BEGIN_OLE_MESSAGE\n$oleMsg\nEND_OLE_MESSAGE));
    print STDERR $erTxt;
    last EF;
  }
 
  foreach my $hit (@main::userFields) {
    printf  qq/ %11.11s: %-64.64s\n/, $hit, $ldap->{"$hit"};
  }



                
__________________________________
Do you Yahoo!? 
Meet the all-new My Yahoo! - Try it today! 
http://my.yahoo.com 
 

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to