• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 968
  • Last Modified:

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

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
Bea
Asked:
Bea
  • 3
  • 2
  • 2
  • +1
1 Solution
 
snifferproCommented:
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
 
BeaAuthor Commented:
No, it did not change anything, the output looks the same
0
 
snifferproCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
BeaAuthor Commented:
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
 
jmcgOwnerCommented:
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
 
BeaAuthor Commented:
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
 
jmcgOwnerCommented:
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
 
PashaModCommented:
Question closed and points refunded

PashaMod
CS Moderator
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now