locked
I need a VB script to remove the perticular users from the perticular group from the windows active directory. RRS feed

  • Question

  • I need a VB script to remove the perticular users from the perticular group from the windows active directory.

    I have got one script which is pasted below:

    Remove AD LDS User from AD LDS Group.

    Option Explicit

    Dim objADAM   ' Binding object.
    Dim objGroup  ' Group object.
    Dim objUser   ' User object.
    Dim strGroup  ' Group.
    Dim strPath   ' Binding path.
    Dim strOU     ' Organizational unit.
    Dim strUser   ' User.

    ' Construct the binding string.
    strPath = "LDAP://localhost:389/O=Fabrikam,C=US"

    WScript.Echo "Bind to: " & strPath

    ' Specify User.
    strUser = "CN=TestUser"

    ' Specify Group.
    strGroup = "CN=TestGroup,OU=TestOU"

    WScript.Echo "Remove:  " & strUser
    WScript.Echo "          from"
    WScript.Echo "         " & strGroup

    On Error Resume Next

    ' Bind to root.
    Set objADAM = GetObject(strPath)

    ' Output error if bind fails.
    If Err.Number <> vbEmpty Then
        WScript.Echo "Error:   Bind failed."
        WScript.Quit
    End If

    ' Remove User from Group.
    Set objGroup = objADAM.GetObject("group", strGroup)
    Set objUser  = objADAM.GetObject("user", strUser)
    objGroup.Remove objUser.AdsPath

    ' Output success or error.
    If Err.Number <> vbEmpty Then
        WScript.Echo "Error:   Remove failed."
    Else
        WScript.Echo "Success: User removed from group."
    End If

     

    Note:-It throws an error as "Binding is failed",and comes out from the execution. Please let me know what I need to modify in this script.My intension is only to remove the perticular users from the perticular group from the windows active directory.

    Thnx

    Raj

    • Moved by Bill_Stewart Monday, October 20, 2014 5:32 PM This is not "fix script for me" forum
    Sunday, September 14, 2014 2:31 PM

Answers

  • I recommend asking your admin to just use ADUC to remove a user.

     I suspect that you do not hav access to the server or you are accessing the wrong server.  Your Admin can do this for you in about 10 seconds.

    If you are trying to learn scripting then I recommend learning PowerShell as VBScript is quickly going out of use and PowerShell is a requirement for all future technical management.

    Here are resources to help you learn to script.

    http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx

    This forum is not set up to provide free script repair.  It is to support technicians who use script in their work.  It is not a Microsoft support forum.


    ¯\_(ツ)_/¯

    • Proposed as answer by Sam Boutros Sunday, September 14, 2014 5:11 PM
    • Marked as answer by Just Karl Tuesday, December 23, 2014 9:57 PM
    Sunday, September 14, 2014 2:51 PM

All replies

  • I recommend asking your admin to just use ADUC to remove a user.

     I suspect that you do not hav access to the server or you are accessing the wrong server.  Your Admin can do this for you in about 10 seconds.

    If you are trying to learn scripting then I recommend learning PowerShell as VBScript is quickly going out of use and PowerShell is a requirement for all future technical management.

    Here are resources to help you learn to script.

    http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx

    This forum is not set up to provide free script repair.  It is to support technicians who use script in their work.  It is not a Microsoft support forum.


    ¯\_(ツ)_/¯

    • Proposed as answer by Sam Boutros Sunday, September 14, 2014 5:11 PM
    • Marked as answer by Just Karl Tuesday, December 23, 2014 9:57 PM
    Sunday, September 14, 2014 2:51 PM
  • This may also be an ADAM implantation of the script.  ADAM is not AD.  The "Gets" will not work on AD as on ADAM.

    ¯\_(ツ)_/¯

    Sunday, September 14, 2014 6:31 PM