use exec for dsadd

Posted by Daryl Gill on Stack Overflow See other posts from Stack Overflow or by Daryl Gill
Published on 2012-11-17T16:49:52Z Indexed on 2012/11/17 17:00 UTC
Read the original article Hit count: 316

Filed under:
|

I'm Programming on a Windows Server 2008 and I wish to have a WebUI to interact with the domains active directory.

One of my main problems is this that i'm using dsadd from a HTML form but this is no succeeding. I know my command is correct, I have tested it out on the Servers Command line

My Code is As Below:

    if (isset($_POST['Submit']))
    {
        $DesiredUsername = $_POST['DesiredUsername'];
        $DesiredPassword = $_POST['DesiredPassword'];
        $DU = "{$DesiredUsername}";        // Desired Username
        $OU = "PHPCreatedUsers";          // Domain OU
        $DC1 = "slayerserv";             // Domain Part one 
        $DC2 = "local";                 // Domain Part Two
        $PWD = "{$DesiredPassword}";   // Password
        $ExecScript = 'dsadd user cn=$DesiredUsername,cn=PHPCreatedUsers,dc=slayerserv,dc=local -disabled no -pwd $DesiredPassword -mustchpwd yes';
        exec($ExecScript, $output);
        mysql_query("INSERT INTO addedusers (`ID`, `DU`, `OU`, `DC1`, `DC2, `PWD`) 
                    VALUES ('', '$DU', '$OU', '$DC1', '$DC2', '$PWD')");
        echo "<br><br>";
        print_r($output);

    #   echo "User: $DesiredUsername Has been Created";
    }

When I print_r($output); it Returns a blank array:

Array ( )

Could anyone provide me with a solution or point me in the right direction?

++++

Below is a working example of my usage of exec

        $Script = 'ping 127.0.0.1 -n 1';
    exec($Script, $Output);
    print_r($Output);

print_r($Output); Gives:

Array ( [0] => [1] => Pinging 127.0.0.1 with 32 bytes of data: [2] => Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 [3] => [4] => Ping statistics for 127.0.0.1: [5] => Packets: Sent = 1, Received = 1, Lost = 0 (0% loss), [6] => Approximate round trip times in milli-seconds: [7] => Minimum = 0ms, Maximum = 0ms, Average = 0ms )

© Stack Overflow or respective owner

Related posts about php

Related posts about exec