use Win32::OLE qw (in); use CGI qw(:standard); print header; print start_html('Active Directory query results'); my $theLookupID = param('theLookupID'); my $strName = $theLookupID; my $strBase = ";"; # BaseDN should be the search base my $strFilter = "(&(objectCategory=user)(samaccountname=$strName));"; # Valid LDAP search filter my $strAttrs = "AdsPath,cn;"; # Comma-seperated list my $strScope = "Subtree"; # Should be on of Subtree, Onelevel or Base my $oUser; $Win32::OLE::Warn = 3; my $objConn = Win32::OLE->CreateObject("ADODB.Connection"); $objConn->{Provider} = "ADsDSOObject"; $objConn->Open; my $objRS = $objConn->Execute($strBase . $strFilter . $strAttrs . $strScope); $objRS->MoveFirst; while (not $objRS->EOF) { print $objRS->Fields(1)->Value," - "; $strLdap = $objRS->Fields(0)->Value; $oUser = Win32::OLE->GetObject("$strLdap"); print "$oUser->{samaccountname}
"; $objRS->MoveNext; } print end_html;