martavoi
martavoi

Reputation: 7082

Add domain machine user to local admins

I have two machines, say in the company domain CorpotateDomain. First machine: first.CorpotateDomain.com Second: second.CorpotateDomain.com

I want to add PrimUser from the first one to administrators group for second machine using powershell. And then i want to shutdown second machine from the first one (login using PrimUser) using the shutdown utility or stop-computer cmdlet. (Or, for example, restart iis remotely)

Is it possible, and what command should i use to add domain users to admins?

p.s. i tried:

$user = "WinNT://first.CorpotateDomain.com/PrimUser"
$group = New-Object System.DirectoryServices.DirectoryEntry("WinNT://./Administrators")
$group.PSBase.Invoke("Add",$user)

Upvotes: 0

Views: 2393

Answers (2)

Sean Hall
Sean Hall

Reputation: 7878

Set $user to the user's distinguished name, something like CN=PrimUser,CN=Users,DC=CorporateDomain,DC=com.

Upvotes: 0

Loïc MICHEL
Loïc MICHEL

Reputation: 26120

You can add a domain user to the local admin group but i don't think you can add a local user of another computer.

$user=[ADSI]"WinNT://domain/PrimUser"
$group=[ADSI]"WinNT://./Administrators"
$group.Psbase.Invoke("Add",$user.Psbase.path)

Upvotes: 2

Related Questions