Afla daca un utilizator este in unul sau mai multe grupuri in ActiveDirectory folosind POWERSHELL

Configurare noua (How To)

Situatie

Afla daca un utilizator este in unul sau mai multe grupuri in ActiveDirectory
 folosind POWERSHELL:



$Groups = "Group1","Group2"


$GroupHash = @{}
ForEach ($Group in $Groups)
{   $GroupHash.Add((Get-ADGroup $Group).distinguishedName,(New-Object PSObject -Property @{ GroupName = $Group;Count = 0 }))
}

$Results = ForEach ($User in (Get-ADUser -Filter * -Properties MemberOf))
{   $NotFound = $true
    ForEach ($Group in $User.MemberOf)
    {   If ($GroupHash.ContainsKey($Group))
        {   $NotFound = $false
            Break
        }
    }
    If ($NotFound)
    {   $User
    }
}
$Results | Select SamAccountName,Name,distinguishedName | Sort Name

Solutie

Tip solutie

Permanent

Voteaza

(7 din 19 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?