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
Post a Comment