Please try below PowerShell as administrator.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$WebURL = "site collection URL"
$Web = Get-SPWeb $WebURL
$ADGroupCollection= @()
$ReportPath ="C:\ADGroups.csv"
#Get all AD Groups from the site collection
$ADGroups = Get-SPUser -Web $WebURL | Where { $_.IsDomainGroup -and $_.displayName -ne "NT AUTHORITY\authenticated users" -and $_.displayName -ne "Everyone" -and $_.Roles -ne "1" }
#Iterate through each AD Group
foreach($Group in $ADGroups)
{
Write-host "Found AD Group:" $Group.DisplayName
#Get Direct Permissions
$Permissions = $Group.Roles | Where { $_.Name -ne "Limited Access" } | Select -ExpandProperty Name
#Send Data to an object array
$ADGroup = new-object psobject
$ADGroup | add-member noteproperty -name "Group Name" -value $Group.DisplayName
$ADGroup | add-member noteproperty -name "Permissions" -value ($Permissions -join ",")
#Add to Array
$ADGroupCollection+=$ADGroup
}
#Export Data to CSV
$ADGroupCollection | export-csv $ReportPath -notypeinformation
Write-host "SharePoint Security Groups data exported to a CSV file at:"$ReportPath -ForegroundColor Cyan
Result:
