0%
Delete a Group

Delete a Group

This guide shows you how to delete a group in Active Directory with PowerShell.

10-15 min

Delete an Active Directory Group with PowerShell

In this course, we'll learn how to use PowerShell to delete Active Directory (AD) groups with the Remove-ADGroup command. These commands let you delete specific groups, either individually or through automation, based on certain criteria.


Command Summary

# Verifies the existence and information of the group "GroupeTest1"
Get-ADGroup -Identity GroupeTest1

# Deletes the group "GroupeTest1"
Remove-ADGroup -Identity GroupeTest1

# Checks again to confirm the deletion
Get-ADGroup -Identity GroupeTest1

# Retrieves all groups in the "OUTest" organizational unit
$Groupes = Get-ADGroup -Filter * -SearchBase "OU=OUTest,DC=lab,DC=lan"

foreach($Groupe in $Groupes)
{
   # Counts the number of members in each group
   $NombreMembre = (Get-ADGroupMember -Identity $Groupe | Measure-Object).count

   Write-Host "Le groupe $($Groupe.Name) contient $($NombreMembre) membre(s)"
Link copied!