I am working on a script that takes a powershell variable and uses it in a script block running the net command.
Here is the code:
$User = "domain\user" Invoke-Command -ComputerName $ComputerName -ScriptBlock { net localgroup administrators $User /add } -Credential $cred
When I run it, this is the error message I get:
The group already exists. + CategoryInfo : NotSpecified: (The group already exists.:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError + PSComputerName : GMCR77569 More help is available by typing NET HELPMSG 2223.
So it appears that the net command is trying to create the administrators group. I haven't found much on Google for that.
Also, I am using Invoke-Command because I need to be able to pass credentials.
I am sure this is something simple, but I cannot figure it out. Thank you in advance!