0

How to add user to active directory group?

How can I add user to the Active Directory by the javascript code.

I have got a script which adding to Sharepoint Group, but how Could I do it with Active Directory Group:

    <asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<script type="text/ecmascript" language="ecmascript">

var user;
var FlashGroup;

function runCode() {

     var clientContext = new SP.ClientContext();
     var groupCollection = clientContext.get_web().get_siteGroups();

     FlashGroup = groupCollection.getByName('Group Sharepoint');
     user = clientContext.get_web().get_currentUser();
     var userCollection = FlashGroup.get_users();
     userCollection.addUser(user);

     clientContext.load(user);
     clientContext.load(FlashGroup);
     clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceededZapisz), Function.createDelegate(this, this.onQueryFailed));

}

function onQuerySucceededZapisz() {
    alert(user.get_title() + " został dodany do " + FlashGroup.get_title());
}

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

</script>

    <input id="Button11" type="button" class="Zapisz" value="Zapisz mnie do grupy" onclick="runCode()" />

</asp:Content>
  • I'm edit my Question Lindgren – Grzegorz Z Feb 5 '15 at 9:40
0

It depends on, which version of AD you have. For example, in Azure AD you can use REST methods, like this one. In Windows 2008 R2 there is a web service interface for AD, that other components (like the AD PowerShell CmdLets) use as well.

If you don't have (or don't like) these ones, you can create your own wrapper web / WCF services, or even extend the client object model with this functionality.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.