Загрузка данных


# Список групп для проверки (можно расширить при необходимости)
$privilegedGroups = @("Domain Admins", "Enterprise Admins", "Administrators")

foreach ($groupName in $privilegedGroups) {
    try {
        $members = Get-ADGroupMember -Identity $groupName -Recursive -ErrorAction Stop | Where-Object {$_.objectClass -eq "user"}
        foreach ($member in $members) {
            $user = Get-ADUser -Identity $member.distinguishedName -Properties AccountNotDelegated, DisplayName, SamAccountName
            if (-not $user.AccountNotDelegated) {
                [PSCustomObject]@{
                    Group          = $groupName
                    DisplayName    = $user.DisplayName
                    SamAccountName = $user.SamAccountName
                    AccountNotDelegated = $user.AccountNotDelegated
                }
            }
        }
    } catch {
        Write-Warning "Не удалось обработать группу $groupName : $_"
    }
}







Get-ADUser -Filter {AdminCount -eq 1} -Properties AccountNotDelegated, AdminCount | 
    Where-Object {-not $_.AccountNotDelegated} | 
    Select-Object Name, SamAccountName, AdminCount, AccountNotDelegated