?
Solved

Win32::OLE how to print AD user's lastLogoff date?

Posted on 2003-03-07
9
Medium Priority
?
966 Views
Last Modified: 2007-12-19
Shortly:

In my ActivePerl program I get the output like this:
Win32::OLE=HASH(0x1b7c654)
while I expected to it to be a valid date.
How can I make a date of it?

Details:

My program is simple:

use Win32::OLE 'in';
my $adsobj = Win32::OLE->GetObject('LDAP://MyServer/OU=OnlyUsers,DC=my,DC=domain,DC=com';
foreach my $child (in $adsobj)
{
    print $child->{Name}."\n";
    print $child->{lastLogoff}."\n";
}

the output looks like this:
CN=securitytest
Win32::OLE=HASH(0x1b7c654)


0
Comment
Question by:Bea
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 1

Expert Comment

by:snifferpro
ID: 8098240
Try adding this line to your script

use Win32::OLE::Variant;

but you should know that this object doesn't replicat .
so if you have more than one Domain Controler You need to get the value from all domain controler .

0
 

Author Comment

by:Bea
ID: 8109461
No, it did not change anything, the output looks the same
0
 
LVL 1

Expert Comment

by:snifferpro
ID: 8118656
try this ....

use Win32::OLE;
use Win32::OLE::Variant;

$AdsPath = "WinNT://MyDomain/MyServer,computer";
$c = Win32::OLE->GetObject($AdsPath) or die "Unable to get $AdsPath\n";
foreach $adsobj (in $c){
    print $adsobj->{Name}, "\n" if ($adsobj->{Class} eq "User");
    print $adsobj->{LastLogin}, "\n" if ($adsobj->{Class} eq "User");
}

just change MyDomain to your domain name and MyServer to your domain controler name .
notice its WinNT quiery NOT a LDAP quiery .
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Bea
ID: 8136426
THank you. It works when I use WinNT namespace. But I prefare to do it in LDAP, and I am trying to investigate it further.

So far I have found in the internet that the problem is perhaps with the long integer format that is returned in the lastLogoff and other date related records.

I have even wrote a VB macro just in order to compare how it will behave. And in VB there is also an error, exactly with date related records.

Here is the piece of the code:

Set obj = GetObject _
("LDAP://MyServer/CN=test,OU=OnlyUsers,DC=my,DC=domain,DC=com")
WScript.echo obj.Name
WScript.echo obj.lastLogon

here we get an error, but:

WScript.echo obj.lastLogon.lowPart & obj.lastLogon.highPart

the above instruction echoes a long number.

So I only need to know how to produce it in Perl and how to convert it to a date...

Bea
0
 
LVL 20

Expert Comment

by:jmcg
ID: 9697523
Nothing has happened on this question in over 7 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
PAQ, refund points (as interesting, but ultimately not answered to asker's satisfaction).

Please post any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0
 

Author Comment

by:Bea
ID: 9700305
I do not have an option to refund points (or I cannot find it, being logged in), i have only the option to split points.
0
 
LVL 20

Expert Comment

by:jmcg
ID: 9704569
Please see the Experts-Exchange help page on closing questions:

http://www.experts-exchange.com/help.jsp#hs5

The PAQ/refund action is something a moderator can do, if you request it or, if a question has been abandoned and a cleanup volunteer recommends it. In this case, I thought the responses included some solutions that we should keep in the database (PAQ) even though you were looking for something else.

You might find it fruitful to try the question again, perhaps when your points are refunded.
0
 

Accepted Solution

by:
PashaMod earned 0 total points
ID: 9741607
Question closed and points refunded

PashaMod
CS Moderator
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question