Hey all... have been spending quite some time searching around for some guidance to what should be something easy for Powershell... adding a user to the local admin group of a computer.
background. I do have admin rights to the workstation I'm testing on and using Powershell V2.
I've seen a number of blog posts and snippets from the Microsoft Scripting guy and Scott Hanselman and a bunch of other well respected folks. At the moment I have this snippet that I'm working with:
$computer = [ADSI]("WinNT://" + $strComputer + ",computer")
$strUser = "TWtest"
Set objGroup=GetObject("WinNT://" & $computer.name & "/Administrators")
Set objUser=GetObject("WinNT://$strUser")
Fairly straightforward I thought. I'm going to want to add a domain user to a bunch of servers so I'm getting the computername and using that as a variable. I'll prepopulate the username (in this case TWtest
The problem I'm running into is that I'm getting the following error:
Unexpected token '&' in expression or statement
It obviously points to line 3 (and then line 4), yet this seems to be a constant with every post I've seen... to concatenate the object using the & character.
What am I doing wrong or just not understanding??
Or is there an easier way to accomplish this?
Thanks