powershell add group to local admin group

how do I remotely use powershell to add a domain group to the local admin group on a machine?

thanks

June 11th, 2013 7:13pm

Do you mean something like this:

invoke-command -ComputerName $RemoteComputerName -Command {net localgroup administrators $mydomain\$myusername /add}

replace $variables with the appropriate values?

Free Windows Admin Tool Kit Click here and download it now
June 11th, 2013 7:44pm

If powershell remoting (or whatever its called) isnt configured on the machine to run against, then I believe Invoke-Command will not work
June 11th, 2013 8:09pm

If powershell remoting (or whatever its called) isnt configured on the machine to run against, then I believe Invoke-Command wil
Free Windows Admin Tool Kit Click here and download it now
June 11th, 2013 8:14pm

If powershell remoting (or whatever its called) isnt configured on the machine to run against, then I believe Invoke-Command will not

June 11th, 2013 8:19pm

Here's the ADSI method:

$remoteComputer = ""
$fqdn = ""
$groupName = ""
([ADSI]"WinNT://$remoteComputer/Administrators,group").Add("WinNT://$fqdn/$groupName")


EDIT: This doesn't require remoting to be configured.
Free Windows Admin Tool Kit Click here and download it now
June 11th, 2013 11:03pm

When using above, I got:

[DBG]: PS C:\>> $remoteComputer = 'xxx.xxx.xxx.xxx'
[DBG]: PS C:\>> $groupname = 'Admin-Group'
[DBG]: PS C:\>> $fqdn = 'subdomain.domain.com'
[DBG]: PS C:\>> ([ADSI]"WinNT://$remoteComputer/Administrators,group").Add("WinNT://$fqdn/$groupName"):

Exception calling "Add" with "1" argument(s): "Access is denied.

"

At line:1 char:1

+ ([ADSI]"WinNT://$remoteComputer/Administrators,group").Add("WinNT://$fqdn/$group ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException

+ FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI

 

I am wondering how $remoteComputer authenticate?

November 5th, 2013 10:20pm

Thanks Mike.  This worked perfectly for me.

Free Windows Admin Tool Kit Click here and download it now
December 17th, 2013 9:18pm

Thanks Mike.  This worked perfectly for me.


Cheers, glad it worked out.
December 17th, 2013 9:34pm

This worked great for me (I had to update half a dozen machines that are in separate offices, 30 minutes apart) thank you!!
Free Windows Admin Tool Kit Click here and download it now
April 6th, 2015 3:53pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics