Adding memberships to a local account

Hi All,
I am new to powershell. I created a code to add membership to an existing account. However, account is a member of Users group by default so i tricked the code but it gives me an error
if($local_groups){$groups="$local_groups" -split(",");foreach($group in $groups){ if($group -ne ‘Users’) {net localgroup $group $local_acc /add} }};

ERROR: + invoke-command -session $session_993 -scriptBlock {if (){$groups="" -split(",…
+missing condition in if statement after ‘if (’
At line:1 chat:57

I am stuck and clueless… Can you please assist?

Thanks a lot in advance,

You could always use the ADSI provider and do something like this:

$Group = [ADSI]"WinNT://,group"
$User = [ADSI]"WinNT://,user"

Thanks for your response Paul.these are the local groups and local accounts only.

I wrote something a while back that was done with Sapien Powershell studio (first gui I have ever done) and I posted this on script center.

This script adds users to local groups using WMI. You can also see this same script on Git Hub GIST post as well:

Hope this gets you what you need.

Because the script is hitting wmi it’ll require standard slashes when calling add delete or list:

In the form of: group/username in the gui tool.

What Paul posted is for local accounts. Be careful when tricking scripts.