Adam Levitt
Adam Levitt

Reputation: 10476

Powershell Add Local Group to Local Group

I'm able to properly add a local user to a local group on my machine, but I can't add a local group to another local group. What is the syntax for this?

$targetGroup = [ADSI]"WinNT://$computerName/$targetGroupName,group"    
$targetGroup.Add("WinNT://$computerName/$groupName")

The above results in this error:

Exception calling "Add" with "1" argument(s): "A new member could not be added to a local group because the member has the wrong account type.

I'm trying to add a local group to a local group, in Windows Server 2012.

Upvotes: 1

Views: 3495

Answers (2)

Eric
Eric

Reputation: 239

You can nest domain groups, but local group nesting is not supported. This technet article explains in detail.

http://technet.microsoft.com/en-us/library/ee681621(v=ws.10).aspx

Have you considered listing all the users of the "subgroup" and adding them to the target group? This obviously would not create a permanent linking like a sub group would. But it would ensure each member of the "subgroup" are members of the target group at the time the script is run.

Upvotes: 1

briantist
briantist

Reputation: 47792

Local groups cannot be added to other local groups. This is a limitation of Windows. It's not that you don't have to right code; it just can't be done.

Reference

A local group cannot be found if it is nested inside another group on a Windows Server-based or Windows-based client

Upvotes: 1

Related Questions