Skip to content

Instantly share code, notes, and snippets.

@stevebauman
Last active March 22, 2019 13:38
Show Gist options
  • Save stevebauman/2fd9d9faee2a916f357407e0e8993826 to your computer and use it in GitHub Desktop.
Save stevebauman/2fd9d9faee2a916f357407e0e8993826 to your computer and use it in GitHub Desktop.
Create a security group using Adldap2

Using Adldap2:

use Adldap\Laravel\Facades\Adldap;

$dn = "CN=".$groupName.",OU=AclGroups,".ACL_OU_AD;

$group = Adldap::make()->group([
    'dn' => $dn,
    'cn' => $groupName,
    'samaccountname' => $groupName,
    'msExchextensioncustomattribute1' => $userSID,
]);

if ($group->save()) {
    // Created
}

Using Raw LDAP Commands with Adldap2:

use Adldap\Laravel\Facades\Adldap;

$conn = Adldap::getConnection();

$add = [
    'cn'=> $groupName,
    'samaccountname' => $groupName,
    'objectClass' => 'Group',
    'msExchextensioncustomattribute1' =>$userSID
];

$dn = "CN=".$groupName.",OU=AclGroups,".ACL_OU_AD;

$result = $conn->add($ldapConnection, $dn, $add);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment