http://qs321.pair.com?node_id=906766

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

when i try to get the lastlogoff/lastlogon/whencreated properties i get smothing like this result:Win32::OLE=HASH(0x51791e8) other properties works fine, any idea why? and how to solve it?

#!/usr/bin/perl use Win32::OLE::Variant; $userObject = Win32::OLE->GetObject("LDAP://CN=<cn>,OU=<ou>,DC=bateman +,DC=co, DC=il"); $data1 = $userObject->{lastlogoff}; print $data1;

Replies are listed 'Best First'.
Re: Newbie, AD problem
by bingos (Vicar) on May 26, 2011 at 10:10 UTC

    lastLogon is stored as a large integer that represents the number of 100 nanosecond intervals since January 1, 1601 (UTC). A value of zero means that the last logon time is unknown.

    I use an incantation like follows to get date type values out of AD:

    sub msqtime2perl { # MicroSoft QuadTime to Perl my $foo = shift; my ($high,$low) = map { $foo->{ $_ } } qw(HighPart LowPart); return unless $high and $low; return ((unpack("L",pack("L",$low)) + unpack("L",pack("L",$high)) * (2 ** 32))) / 10000000) - 11644473600; } if ( $userObject->{lastLogon} and $userObject->{lastLogon}->{HighPart} + ) { $epochtime = msqtime2perl( $userObject->{lastLogon} ); }
Re: Newbie, AD problem
by choroba (Cardinal) on May 26, 2011 at 08:38 UTC
      keep getting : $VAR1 = bless( do{\(my $o = 52933736)}, 'Win32::OLE::Variant' ); 52933736 - change every time i run the script any other ideas?
Re: Newbie, AD problem
by Ratazong (Monsignor) on May 26, 2011 at 09:12 UTC

    If you want to read a date from an excel cell using WIN32::OLE, you should use the following

    my $date = $Sheet->Range($r)->{FormulaR1C1}; # dont use Value for +dates
    Possibly you have to do something similar for the properties ...

    HTH, Rata