can you be more clear?
do you want to remove security groups from Microsoft Entra ID (that also exists in Windows server or vice versa)
List Security Groups from Windows Server AD and remove them from Azure AD
# Connect to Azure AD
Connect-AzureAD
# Get all group names from Windows Server AD
$ADGroups = Get-ADGroup -Filter 'GroupCategory -eq "Security"' | Select -ExpandProperty Name
foreach ($group in $ADGroups) {
# Find the group in Azure AD
$AzureGroup = Get-AzureADGroup -Filter "DisplayName eq '$group'" -ErrorAction SilentlyContinue
# Check if the group exists in Azure AD and remove it
if ($AzureGroup) {
Remove-AzureADGroup -ObjectId $AzureGroup.ObjectId
Write-Host "Group '$group' removed from Azure AD."
} else {
Write-Host "Group '$group' not found in Azure AD."
}
}
List Security Groups from Azure AD and Remove from Windows Server AD
# Connect to Azure AD
Connect-AzureAD
# Get all group names from Azure AD
$AzureADGroups = Get-AzureADGroup -All $true | Where-Object { $_.SecurityEnabled -eq $true } | Select -ExpandProperty DisplayName
foreach ($group in $AzureADGroups) {
# Check if the group exists in Windows Server AD
$ADGroup = Get-ADGroup -Filter "Name -eq '$group'" -ErrorAction SilentlyContinue
# Check if the group exists in Windows Server AD and remove it
if ($ADGroup) {
Remove-ADGroup -Identity $ADGroup.DistinguishedName
Write-Host "Group '$group' removed from Windows Server AD."
} else {
Write-Host "Group '$group' not found in Windows Server AD."
}
}
if you can give more detail i can be more accurate