1.For a specific SharePoint group, please run below PowerShell.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$GroupName = "group name"
$SiteColl = Get-SPWebApplication "web application URL" | Get-SPSite -Limit All | Get-SPWeb -Limit All
ForEach($_ in $SiteColl) {
If($_.SiteGroups[$GroupName] -ne $null)
{
$_.SiteGroups.Remove($GroupName)
}
}
2.For a specific AD group, please run below PowerShell.
Note: Go to site settings -> Site permission -> Select the AD group -> Find the AD group account.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
Function Delete-UserFromAllSites([string]$WebAppURL, [string]$UserAccount, [bool]$ScanOnly)
{
$WebApp = Get-SPWebApplication $WebAppURL
foreach ($Site in $WebApp.Sites)
{
try
{
$ErrorActionPreference = "Stop"
$User = $Site.RootWeb.SiteUsers | Where-Object {$_.LoginName -eq $UserAccount}
if($User -ne $null)
{
$Site.RootWeb.SiteUsers.Remove($UserAccount)
Write-Host "User Deleted from: $($site.Rootweb.URL)"
}
}
catch
{
#Write error message on screen and to a LOG file
write-host "Error Deleting user from site collection: $($site.rootweb.url)"
}
finally
{
$ErrorActionPreference = "Continue"
$site.Dispose()
}
}
}
Delete-UserFromAllSites "web application URL" "AD group account" $true
If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.