sub ad_modify { # To change a single value in AD use Win32::OLE; my $dn = $_[0]; # The object DN my $attrib = $_[1]; # The attribute to change my $value = $_[2]; # The attributes new value my ($object); $object = Win32::OLE->GetObject("$dn"); $object->{$attrib} = "$value"; $object->SetInfo; # Don't forget to set the values } sub ad_get_attrib { # For returning Attribute Values.... use Win32::OLE; my $dn = $_[0]; # The object DN my $attrib = $_[1]; # The attribute in question my ($object,$result); $object = Win32::OLE->GetObject("$dn"); if ($object->{$attrib}) { # If this Attribute actually exists.... $result = $object->Get("$attrib"); } return $result; } sub ad_search { # To search AD and return a pre-determined value use Win32::OLE; 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 }