I know this is an old question, but I too stumbled across this problem this past week. The above answers were helpful but not complete. I dug into it more and believe I have a script that fully cleans everything up.
$web = "https://sp.domain.com/sites/erictest126"
# The Web
$spweb = Get-SPWeb $web
$communityFeatureVisibleInUI = "961d6a9c-4388-4cf2-9733-38ee8c89afd4"
$communityFeatureHiddenInUI = "4326e7fc-f35a-4b0f-927c-36264b0a4cf0"
# Disable the Community Site feature
if(Get-SPFeature -Identity $communityFeatureVisibleInUI -Web $spweb.Rootweb.Url -ErrorAction SilentlyContinue){
Write-Host "Deactivating Community Site Feature on" $web
Disable-SPFeature -Identity $communityFeatureVisibleInUI -Url $web -Confirm:$False
}
# The lists
$badgeList = $spweb.Lists["Badges"]
$categoriesList = $spweb.Lists["Categories"]
$membersList = $spweb.Lists["Community Members"]
$discussionsList = $spweb.Lists["Discussions List"]
$abuseList = $spweb.Lists["Reports List"]
$sitePages = $spWeb.Lists["Site Pages"]
# Holding arrays
$communityPages = @()
$communityMembers = @()
$discussionsFields = @()
$membersIndexes = @()
$discussionsIndexes = @()
# Disable Content Types on lists
$membersList.ContentTypesEnabled = $false
$membersList.Update()
$discussionsList.ContentTypesEnabled = $false
$discussionsList.Update()
$abuseList.ContentTypesEnabled = $false
$abuseList.Update()
# Find the feature generated pages
foreach($page in $sitePages.Items){
if($page.Name -eq "Community Home.aspx" -or $page.Name -eq "About.aspx" -or $page.Name -eq "Topic.aspx" -or $page.Name -eq "Category.aspx" -or $page.Name -eq "Categories.aspx" -or $page.Name -eq "Members.aspx"){
# Add it to the communityPages array, the item cannot be deleted from the collection proper
$communityPages += $page
}
}
# Delete the community pages
foreach($communityPage in $communityPages){
$communityPage.Recycle()
}
# Find any created Community Members
foreach($cm in $membersList.Items){
# Add it to the communityPages array, the item cannot be deleted from the collection proper
$communityMembers += $cm
}
# Delete the created members
foreach($member in $communityMembers){
$member.Recycle()
}
# Remove the hidden Badge list, this is the easiest to remove
$badgeList.AllowDeletion = $true
$badgeList.Update()
$badgeList.Delete()
# Remove the Categories List
$categoriesList.AllowDeletion = $true
$categoriesList.Update()
$categoriesList.Delete()
# Remove the Reports List
$abuseList.AllowDeletion = $true
$abuseList.Update()
$abuseList.Delete()
# Column fixup
$BadgeColumn = $membersList.Fields.GetFieldByInternalName("GiftedBadgeLookup")
$BadgeColumn.AllowDeletion = $true
$BadgeColumn.Sealed = $false
$BadgeColumn.Delete()
$discussionDependantColumns = @("AbuseReportsCommentsLookup","AbuseReportsReporterLookup","AuthorGiftedBadgeLookup","AuthorLastActivityLookup","AuthorMemberSinceLookup","AuthorMemberStatusIntLookup","AuthorNumOfBestResponsesLookup","AuthorNumOfPostsLookup","AuthorNumOfRepliesLookup","AuthorReputationLookup")
foreach($discussionDependantColumn in $discussionDependantColumns){
$LookupColumn = $discussionsList.Fields.GetFieldByInternalName($discussionDependantColumn)
$LookupColumn.AllowDeletion = $true
$LookupColumn.Sealed = $false
$LookupColumn.Delete()
}
# Now the lookup column can be deleted
$ReportColumn = $discussionsList.Fields.GetFieldByInternalName("AbuseReportsLookup")
$ReportColumn.AllowDeletion = $true
$ReportColumn.Sealed = $false
$ReportColumn.Delete()
$MemberLookupColumn = $discussionsList.Fields.GetFieldByInternalName("MemberLookup")
$MemberLookupColumn.AllowDeletion = $true
$MemberLookupColumn.Sealed = $false
$MemberLookupColumn.Delete()
# Deletes the Members column
$MemberColumn = $membersList.Fields.GetFieldByInternalName("Member")
$MemberColumn.AllowDeletion = $true
$MemberColumn.Sealed = $false
$memberColumn.EnforceUniqueValues = $false
$memberColumn.Indexed = $false
$MemberColumn.Delete()
# Delete community members list indicies
foreach($listIndex in $membersList.FieldIndexes){
$membersIndexes += $listIndex.Id
}
foreach($index in $membersIndexes){
$membersList.FieldIndexes.Delete($index)
}
$membersList.AllowDeletion = $true
$membersList.Update()
$membersList.Delete()
foreach($listIndex in $discussionsList.FieldIndexes){
$discussionsIndexes += $listIndex.Id
}
foreach($index in $discussionsIndexes){
$discussionsList.FieldIndexes.Delete($index)
}
# Discussions List column fixup
$Categories = $discussionsList.Fields.GetFieldByInternalName("CategoriesLookup")
$Categories.Indexed = $false
$Categories.AllowDeletion = $true
$Categories.Sealed = $false
$Categories.Delete()
# Finally delete the Discussions List
$discussionsList.AllowDeletion = $true
$discussionsList.Update()
$discussionsList.Delete()
# Disable the hidden Community Site feature, cleans up content type
if(Get-SPFeature -Identity $communityFeatureHiddenInUI -Site $web -ErrorAction SilentlyContinue){
Write-Host "Deactivating Community Site hidden feature on" $web
Disable-SPFeature -Identity $communityFeatureHiddenInUI -Url $web -Confirm:$False
}
Just swap out the url in the first line with your affected site and it should clean up all the garbage.
https://ericjalexander.com/blog/2019/06/27/Removing-Community-Site-Feature