Tuesday, November 19, 2013

Script for adding a domain user account to remote local admin group

Below is a script to make a domain user  admin of a local computer

1) The Computer on which the user needs to be added should have a Static IP
2) The user executing the script should have domain admin rights

------------------------------------------------------------------------------------------------------------
### Domain (edit with your domain)
$Domain = "xxx.com"

### Get machine hostname
$Computer = Read-Host "Enter machinename to add user to local admins"

### Get User account in samaccountname format
$UserName = Read-Host "Enter username to add to local admin group of $Computer"

# Bind to the local Administrators group on the computer.
$Group = [ADSI]"WinNT://$Computer/Administrators,group"

# Bind to the domain user.
$User = [ADSI]"WinNT://$Domain/$UserName,user"

# Add the domain user to the group.
$Group.Add($User.Path)
*****

------------------------------------------------------------------------------------------------------------

No comments:

Post a Comment