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://Server01.contoso.com/Administrators,group"
$User = [ADSI]"WinNT://Server01.contoso.com/UserName,user"
$Group.Add($User.Path)
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.
https://gallery.technet.microsoft.com/scriptcenter/2523b208-2f4a-4b7a-a458-1340e3967636
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.