Group memebership test


hello,

i need test ad user group membership , thinking use code:

$aduser = get-aduser mariusd -properties memberof   if($aduser.memberof -notcontains 'cn=group name,ou=groups,dc=office,dc=intra'){          'is not memeber; need add user group' } else {'is meember'}

then asked self if else didn't need , found better way , found this: http://gallery.technet.microsoft.com/scriptcenter/5adf9ad0-1abf-4557-85cd-657da1cc7df4 complex , ask self: in wrong way ? or function found doing more simple membership test ?

thanks,

marius


hi marius,

your way requires different - , potentially more restrictive - input types (including need have ad cmdlets available). also, detect direct group membership, not nested memberships.

that said, method lot faster code :)

it matter of base input is, how effort justified , internal requirements (compliance, etc.) are.

for example, in case i'd required make average user can use comfortably. means accepting display name input both user , group (also accepting ad information objects of course), switch include group recursion, etc.. , full documentation.

bottom line: it's different script different task. better 1 depends on requirements.

cheers,
fred


there's no place 127.0.0.1



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Error: 0x80073701 when trying to add Print Services Role in Windows 2012 Standard

Disconnecting from a Windows Server 2012 R2 file sharing session on a Windows 7,8,10 machine

Event ID 64,77,1008 Certificates Events Windows Server 2008, 2008R2