Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

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

$
0
0

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


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>