Skip to main content

Delete Group

Deletes a group from Azure Active Directory.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If ContinueOnError property is true, no error is caught when the project is executed even if Catch node is used.

warning

Deleting a group is permanent. All group data, including files in Microsoft 365 groups, will be deleted.

Inputs

  • Access Id - The access ID from the Connect node. Optional if using direct credentials.
  • Group Object Id - Group object ID of the group to delete. Example: 12345678-1234-1234-1234-123456789012

Options

Direct Credentials (optional - alternative to using Connect node):

  • Tenant Id - Azure AD tenant ID (optional if using Access ID)
  • Client Id - Azure AD application client ID (optional if using Access ID)
  • Client Secret - Azure AD application client secret credential (optional if using Access ID)

Output

  • Result - Deletion result message (empty string or success message).

How It Works

The Delete Group node:

  1. Authenticates using either the access ID or direct credentials
  2. Sends a DELETE request to Microsoft Graph API for the specified group
  3. Azure AD permanently deletes the group
  4. All group data is removed (including files for M365 groups)
note

Unlike user deletion, group deletion is immediate and permanent. There is no recycle bin for groups.

Examples

Delete Group by Object ID

Remove a group:

// Using Connect node
access_id = message.access_id
group_object_id = "12345678-1234-1234-1234-123456789012"

// Delete Group node executes

// Output
result = "" // Empty string indicates success

Delete Group with Verification

Verify group before deletion:

group_object_id = "12345678-1234-1234-1234-123456789012"

try {
// Step 1: Get group information
// Get Group node
// Group Object Id: group_object_id

console.log("Found group: " + result.displayName)

// Step 2: Verify it's the right group
if (result.displayName.startsWith("Test - ")) {
// Delete Group node
// Group Object Id: group_object_id

console.log("Group deleted successfully")
} else {
console.log("Group doesn't match criteria, skipping deletion")
}

} catch (error) {
console.log("Group not found or error: " + error.message)
}

Cleanup Temporary Groups

Delete temporary or test groups:

// List All Groups node

// Find temporary groups
temp_groups = []
for (group of result.value) {
if (group.displayName.includes("TEMP") ||
group.displayName.startsWith("Test")) {
temp_groups.push(group)
}
}

console.log("Found " + temp_groups.length + " temporary groups")

// Delete each temporary group
for (temp_group of temp_groups) {
try {
// Delete Group node
// Group Object Id: temp_group.id

console.log("Deleted: " + temp_group.displayName)

// Delay between deletions
// Wait 1 second

} catch (error) {
console.log("Failed to delete: " + temp_group.displayName)
}
}

Bulk Group Deletion

Delete multiple groups from a list:

// List of group IDs to delete
groups_to_delete = [
"12345678-1234-1234-1234-123456789012",
"abcdef12-3456-7890-abcd-ef1234567890",
"fedcba98-7654-3210-fedc-ba9876543210"
]

deleted_groups = []
failed_groups = []

// Loop through groups
for (group_id of groups_to_delete) {
try {
// Get group name for logging
// Get Group node
// Group Object Id: group_id
group_name = result.displayName

// Delete Group node
// Group Object Id: group_id

deleted_groups.push(group_name)
console.log("Deleted: " + group_name)

// Add delay
// Wait 1 second

} catch (error) {
failed_groups.push({id: group_id, error: error.message})
console.log("Failed to delete: " + group_id)
}
}

console.log("Deleted: " + deleted_groups.length)
console.log("Failed: " + failed_groups.length)

Project Cleanup Automation

Delete project groups after project completion:

// Project completion data
completed_projects = [
"Project Alpha",
"Project Beta"
]

// List All Groups node

// Find and delete project groups
for (project_name of completed_projects) {
group_name = project_name + " Team"

// Find the group
found_group = null
for (group of result.value) {
if (group.displayName === group_name) {
found_group = group
break
}
}

if (found_group) {
// Delete Group node
// Group Object Id: found_group.id

console.log("Deleted project group: " + group_name)
} else {
console.log("Project group not found: " + group_name)
}
}

Safe Deletion with Member Check

Only delete groups with no members:

group_object_id = "12345678-1234-1234-1234-123456789012"

// List Group Members node
// Group Object Id: group_object_id

if (result.value.length === 0) {
// No members, safe to delete
// Delete Group node
// Group Object Id: group_object_id

console.log("Empty group deleted")
} else {
console.log("Group has " + result.value.length + " members, not deleting")
}

Tips for Effective Use

  • Verification: Always verify the group before deletion
  • Permanent action: Group deletion is immediate and permanent
  • Object ID required: You must use the group's object ID
  • Logging: Log all deletion operations for audit purposes
  • Error handling: Use Try-Catch to handle groups that don't exist
  • Bulk operations: Add delays between deletions
  • Member check: Consider checking members before deletion
  • Backup data: For M365 groups, export files before deletion

Common Errors and Solutions

"Group Object Id cannot be empty"

Cause: The Group Object Id input was not provided.

Solution: Provide a valid group object ID:

group_object_id = "12345678-1234-1234-1234-123456789012"

"Response Status is not OK - Group not found"

Cause: No group exists with the specified object ID.

Solution:

  • Verify the group object ID is correct
  • Group may have already been deleted
  • Use Try-Catch to handle this gracefully
try {
// Delete Group node
group_object_id = "maybe-deleted-id"
} catch (error) {
console.log("Group already deleted or not found")
}

"Either Client Secret with Tenant ID and Client ID, or Access ID must be provided"

Cause: Neither access ID nor complete credentials were provided.

Solution:

// Option 1: Use Connect node
access_id = message.access_id

// Option 2: Provide all credentials
tenant_id = "your-tenant-id"
client_id = "your-client-id"
// Set Client Secret option from vault

"Insufficient privileges"

Cause: The application doesn't have permission to delete groups.

Solution:

  • Verify your Azure AD app has Group.ReadWrite.All permission
  • Ensure admin consent has been granted
  • Check that it's an Application permission

Best Practices

  1. Verification: Always verify the group exists and is correct before deletion
  2. Logging: Log all deletion operations with timestamps and group details
  3. Error handling: Use Try-Catch blocks for graceful error handling
  4. Audit trail: Maintain records of what was deleted and when
  5. Member check: Verify group has no members or handle member removal
  6. Data backup: For M365 groups, export files before deletion if needed
  7. Throttling: Add delays when deleting multiple groups
  8. Confirmation: Implement confirmation steps for critical deletions
  9. Naming conventions: Use naming patterns to identify deletable groups
  10. Documentation: Document which groups were deleted and why