Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7661087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:33:07+00:00 2026-05-31T13:33:07+00:00

I have created a script in Perl to connect to LDAP, retrieve values and

  • 0

I have created a script in Perl to connect to LDAP, retrieve values and post them to a CSV file. The values I am retrieving via a query are d”distinguished name, userAccountControl & pwdLastSet. I can pull and parse the first two results correctly and post them to the CSV file, but the pwdLastSet is returning WIN32::OLE=HASH(0x…….). I have tired sprintf, hex(), and the results are either the WIN32 value or 0. I am expecting something 18 digits in length. Thanks for the help.

#!/usr/bin/perl
use xSV;
use Win32;
use Win32::OLE;
# use strict;
.
.
.
.  
  while ($line = <GROUPS>) {
        chomp($line);
        if ($line =~ m/^  user  .*/) {
            $line =~ s/^  user.\s//;
            my ($objRootDSE, $strDomain, $strUsername, $objConnection, $objCommand, $objRecordSet, $strDN, $arrSplitResponse, $strLName, $strFName, $strUserType);
            use constant ADS_SCOPE_SUBTREE => 2;
            # Get domain components
            $objRootDSE = Win32::OLE->GetObject('LDAP://RootDSE');
            $strDomain = $objRootDSE->Get('DefaultNamingContext');
            # Get username to search for
            $strUsername = $line;
            # Set ADO connection
            $objConnection = Win32::OLE->new('ADODB.Connection');
            $objConnection->{Provider} = 'ADsDSOObject';
            $objConnection->Open('Active Directory Provider');
            # Set ADO command
            $objCommand = Win32::OLE->new('ADODB.Command');
            $objCommand->{ActiveConnection} = $objConnection;
            $objCommand->SetProperty("Properties", 'Searchscope', ADS_SCOPE_SUBTREE);
            $objCommand->{CommandText} = 'SELECT distinguishedName, userAccountControl, pwdLastSet FROM \'LDAP://' . $strDomain . '\' WHERE objectCategory=\'user\' AND samAccountName = \'' . $strUsername . '\'';
            # Set recordset to hold the query result
            $objRecordSet = $objCommand->Execute;
            # If a user was found - Retrieve the distinguishedName
            if (!$objRecordSet->EOF) {
                $strDN = $objRecordSet->Fields('distinguishedName')->Value;
                $strAcctControl = $objRecordSet->Fields('userAccountControl')->Value;
                $strpwdLS = sprintf($objRecordSet->Fields('pwdLastSet')->Value);
                @arrSplitResponse = split(/,/, $strDN);
                $strLName = substr($arrSplitResponse[0],3);
                if ($strLName =~ m/\\$/) {
                    $strLName = substr($strLName,0,-1);
                }
                $strFName = $arrSplitResponse[1];
                if ($strFName =~ m/OU=/) {
                    $strUserType = $strFName;
                    $strFName = "";
                    $strUserType = substr($strUserType,3);
                } else {
                    $strUserType = substr($arrSplitResponse[2],3);
                    }
                if ($strAcctControl == 512) {
                    $strAcctControl = "Active";
                } else {
                    $strAcctControl = "Disabled";
                }
            } else {
                print "No user found";
            }
            &debug("Match!: $line in $group\n");
            $csv->print_data(
                AccountName => $line,
                LastName => $strLName,
                FirstName => $strFName,
                SYSGenericAcct => $strUserType,
                AccessLevel => $group,
                AccessCapability => "User",
                Description => $desc,
                Status => $strAcctControl,
                LastPwdChange => $strpwdLS
            );
        } else {
            $group = $line;
            chomp($desc = <GROUPS>);
            chomp($group2 = <GROUPS>);
            &debug("$group\n$desc\n$group\n");
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:33:08+00:00Added an answer on May 31, 2026 at 1:33 pm

    Use Net::Ldap to search AD server. It is fast and it is portable. It is possible to search AD server from other hosts, even from linux. It is a fast and mature module.

    You could also do some debug, using Data::Dumper.

    use Data::Dumper;
    …
    print Dumper($strpwdLS);

    I found this thread: http://code.activestate.com/lists/pdk/3876/

    # Calculate password age in days
    my $PWage;
    my $LastPW  = $item->{pwdLastSet};
    my $fRef = ref ($LastPW);
    my ($Hval, $Lval);
    if ($fRef eq 'Win32::OLE' )
    {
       $Hval = $LastPW->HighPart;
       $Lval = $LastPW->LowPart;
       my $Factor = 10000000;   # convert to seconds
       my $uPval = pack("II",$Lval,$Hval);
       my ($bVp, $aVp) = unpack("LL", $uPval);
       $uPval = ($aVp*2**32+$bVp)/$Factor;
       if ($uPval != 0)
       {
          $uPval -= 134774*86400;  #Adjust for perl time!
           my $EpochSeconds = time;
          $PWage = ($EpochSeconds - int($uPval))/(60*60*24) ;
          $PWage =~ s/\..*$//;
       }
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Perl script that reads a command file and restarts itself if
I am generating new xml file using perl script but I have small problem,
I have created a simple perl script. The only thing it does is waiting
I have created an executable (.exe) of a perl script on a 64-bit linux
I have this being created by my perl script. print qq| \$('textarea[name=category$row[0]]').keydown(function(event) { \$(input[value=$row[0]]).attr('checked',
Firstly i have created a sequence in oracle in perl script.I get a error
I have created my own Perl module. I reference it from file Config.pm. When
Related/Possible duplicate: How can I validate dates in Perl? I have created a script
I have a perl script that append text on a file : open (EXFILE,
I have a string containing fully formatted XML data, created using a Perl script.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.