Save the file as “RemoveGroups.ps1”.
#get the site object
$site = Get-SPSite “ http:// yoursitecollection”
#get the group collection details
$groups = $site.RootWeb.sitegroups
#set the location where you have placed the CSV file
$inputCSV ="C:\ ExportGroups.csv"
#import the csv file to dbrows
$dbRows = IMPORT-CSV $inputCSV
Write-Host "Count " $dbRows.Count
write-host -ForegroundColor Green "Starting for Deletion of a group Operation"
#for each of the row in csv file check if the RemoveGroup value is set to Yes.
FOREACH ($dbRow in $dbRows)
{
write-host -ForegroundColor Green "Processing " $dbRow.GroupName
if($dbrow.RemoveGroup -eq "Yes")
{
write-host "Deleting the group :" $dbRow.GroupName
#delete the group
$groups.Remove($dbRow.GroupName)
}
else
{
write-host -ForegroundColor yellow "Skipping for " $dbRow.GroupName
}
}