I'm having trouble getting the lastLogon property of a user in AD using Perl and LDAP. Below is my code. The problem is that I keep getting a blessed Win32::OLE hash returned instead of a number when returning the value of lastLogon. The "hash" has no keys, so I think this might be a mismapping of the data type, but I'm not sure. Has anyone else run into this problem? Am I just doing something monumentally stupid? (BTW, the SimpleDT thing is just my personal function for formatting the results of localtime(). I'm trying to pass it the lastLogon value)
####################################################### use strict; use warnings; no warnings qw(uninitialized); use Win32::OLE; use Win32::OLE::Variant; use Tim::Date_Time; my @dc = qw(dc1 dc2 dc3); foreach my $dc(@dc){ print "Checking $dc...\n\n"; my $ADUser = Win32::OLE->GetObject("LDAP://$dc/OU=Groups and Users,OU=HQ,DC=domain,DC=com") || die; foreach(in($ADUser)){ unless($_->{objectCategory} =~ /Group/i){ my $lastlogon = $_->{lastLogon}; my $name = $_->{name}; $name =~ s/^CN=//; push @{$users{$name}},$lastlogon; } } } open(OUTFILE,">lastlogon.csv") || die; print "Finding last logon...\n"; foreach(sort keys %users){ my $name = $_; print "$name => "; my $lastlogon; foreach my $logon(@{$users{$_}}){ print "$logon,"; if($logon > $lastlogon){ $lastlogon = $logon; } } print "($lastlogon)\n"; $lastlogon = (Date_Time::SimpleDT($lastlogon))[0]; print OUTFILE "$name,$lastlogon\n"; } close OUTFILE; #######################################################