Directory Services

Removing Groups

To remove a group, call the IADsContainer.Delete method of the group parent object.

myComputer.Delete "group", myGroup.Name

The following code example removes a group.

' Deletes (removes) a group object given the ADsPath of the group.
' No action is taken if the object is not a group.
Public Sub DeleteGroup(strGroupADsPath As String)
	Dim obj As IADs
	Dim parent As IADsContainer

	' Bind to the object.
	Set obj = GetObject(strGroupADsPath)

	' If the ADsPath passed is not ot a group object, then exit.
	If "group" <> LCase(obj.Class) Then
		Exit Sub
	End If

	' Bind to the parent of the object.
	Set parent = obj.parent

	' Delete the object.
	parent.Delete obj.Class, obj.Name
End Sub

Be aware that this code example deletes a group without regard to contents; as a best practice, it is recommended that your application require some user interaction to ensure that a delete is not performed unintentionally.