powershell - Check if AD User was part of the AD Group which could be in its sub group -


i query user whether part of group, issue here is.. hard identify whether part of because in many level of group sub group.

example if wanted check if user in "all sales users". in subgroup of "all sales users" > "sales us" > "sales sj" > "prod a" > "item b"

the issue is, there many sub group had open search him. how know whether part of "all sales users"? best if query show hierarchy.

i tried powershell show memberof. not sure how on this.

a recursive powershell implementation, assumes have activedirectory powershell module installed. return common name groups user member of, including nested in example 5 groups returned.

function findgroup($n){     $g = get-adgroup $n;     $parents = get-adgroup -filter {members -eq $g.distinguishedname}     if($parents -eq $null){         return $g.name;     }     else{         $g.name;         $parents | % { findgroup $_ }     } } 

and second function utilise first one:

function findusersgroup($username){     $u = (get-aduser $username -properties memberof).memberof     $u | % { findgroup $_} } 

so if paste above 2 functions powershell window can run

ps c:\> findusersgroup raf 

which return list of groups user member of, including hierarchy:

insideinsidetopgroup insidetopgroup topgroup othergroup 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -