how do I remotely use powershell to add a domain group to the local admin group on a machine?
thanks
Technology Tips and News
how do I remotely use powershell to add a domain group to the local admin group on a machine?
thanks
Do you mean something like this:
invoke-command -ComputerName $RemoteComputerName -Command {net localgroup administrators $mydomain\$myusername /add}
replace $variables with the appropriate values?
If powershell remoting (or whatever its called) isnt configured on the machine to run against, then I believe Invoke-Command wil
If powershell remoting (or whatever its called) isnt configured on the machine to run against, then I believe Invoke-Command will not
Here's the ADSI method:
$remoteComputer = "" $fqdn = "" $groupName = "" ([ADSI]"WinNT://$remoteComputer/Administrators,group").Add("WinNT://$fqdn/$groupName")
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?
Thanks Mike. This worked perfectly for me.
Thanks Mike. This worked perfectly for me.