Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1162
  • Last Modified:

Add a computer account in Active Directory to the local administrator group using PowerShell

Hello. I have a PowerShell script that runs locally on a machine performing several different actions. One of the actions is to add a specific computer account in Active Directory. For example, I have a computer called Desktop that is in the Lab domain. I would like to add a computer account called Server to the local administrator group on Desktop.

I have tried several different approaches without success. Could anyone offer advice?
0
Lorrec
Asked:
Lorrec
  • 2
1 Solution
 
footechCommented:
You should be able to run the following from an elevated prompt on Desktop, where "Server$" is the computer account you wish to add.
$group = [ADSI]"WinNT://./Administrators,group"  
$group.Add("WinNT://Server$,user")

Open in new window

0
 
LorrecAuthor Commented:
Exactly what I needed. Thank you.
0
 
LorrecAuthor Commented:
Thank you for the quick response.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now