sub ad_search { # To search AD and return a pre-determined value my $search_base = $_[0]; # This is the base for our searches my $filter = $_[1]; # This is the valid LDAP filter that we will be applying my $attribute = $_[2]; # This is the attribute that we will be returning my $search_scope = $_[3]; # This is the scope for our search to follow my ($conn, $res, @result, $succ_search); # Variables that we are using as we go $conn = Win32::OLE->new('ADODB.Connection'); # New connection $conn->{Provider} = "ADsDSOObject"; # OLE provider $conn->Open; $res = $conn->Execute($search_base . $filter . $attribute . $search_scope); # This is our search if ($res->EOF) { # If we have found 0 records that match our search $succ_search = 0; # Set our no records found item and return it } else { $succ_search = 1; # So our records found item $res->MoveFirst; # Go to the first record while (not $res->EOF) { # Whie we still have records push (@result, $res->Fields(0)->Value); # Push them to our array $res->MoveNext; # Go to the next one } } return ($succ_search, @result); # Return our success and our array of results }