Deleting groups
The following code sample deletes a group.
- ADSI
-
Import-Module Adaxes # Connect to the Adaxes service $ns = New-Object("Softerra.Adaxes.Adsi.AdmNamespace") $service = $ns.GetServiceDirectly("localhost") # Bind to the group $groupDN = "CN=SalesGroup,CN=Groups,DC=domain,DC=com" $group = $service.OpenObject("Adaxes://$groupDN", $null, $null, 0) # Delete group $group.DeleteObject("ADM_DELETEOBJECTFLAGS_AUTO") - PowerShell
-
Import-Module Adaxes $identity = "SalesGroup" # sAMAccountName # $identity = "CN=SalesGroup,CN=Groups,DC=domain,DC=com" # DN # $identity = "{EB5FEB21-E648-42AD-B86C-89D3C6807953}" # GUID # $identity = "S-1-5-21-573937-2149998-410785" # SID Remove-AdmGroup -Identity $identity -Server "domain.com" ` -AdaxesService localhost -Confirm:$false
The following code sample deletes a group and includes a reason for deletion.
Import-Module Adaxes
# Connect to the Adaxes service
$ns = New-Object("Softerra.Adaxes.Adsi.AdmNamespace")
$service = $ns.GetServiceDirectly("localhost")
# Bind to the group
$groupDN = "CN=SalesGroup,CN=Groups,DC=domain,DC=com"
$group = $service.OpenObject("Adaxes://$groupDN", $null, $null, 0)
# Specify reason for deletion
$reason = [Softerra.Adaxes.Adsi.OperationReasonInfo]::new(
"#1234", # Reason
"Ticket number" # Field label
)
$group.SetReason($reason)
# Delete group
$group.DeleteObject("ADM_DELETEOBJECTFLAGS_AUTO")
See also
- Writing ADSI scripts
- Server-side scripting
- IADsDeleteOps
- INextOperationReason
- Remove-AdmGroup
- Online script repository