Add AD User/Group to Local Administrator Group

The script can use either a plain text file containing a list of computername or a computer name as input and will add the trustee (AD user or group) as an administrator to the specified computer(s). The script will report back errors if the account is already a member.

4.2 Star
72,035 times
Add to favorites
E-mail Twitter Digg Facebook
  • Adding list of groups with servers
    2 Posts | Last post February 11, 2020
    • If I have a list of servers and groups that match is there a good way to modify to pull both.
      Server01, server01_user
      Server02, server02_user
      Server03, server03_user
    • Hello Ryan,
      Assuming that ServerUserList.csv contains at least the following two columns: ServerName and UserName, this command will iterate though this csv file attempting to add the specified user to the computer.
      Import-Csv ServerUserList.csv | ForEach-Object {
          .\Set-ADAccountasLocalAdministrator.ps1 -Computer $_.ServerName -Trustee $_.UserName
      Let me know if that helps you!
  • Credential Pass through
    1 Posts | Last post October 21, 2019
    • Hello,
      can you please help me, how we can pass through Credential in the script.
  • WARNING: The following exception occurred while retrieving member "add": "The network path was not found.
    1 Posts | Last post June 01, 2019
    • $Files= Import-Csv C:\Users\###\Desktop\SQLSERVERS.txt
      Foreach ($File in $Files){
      .\Set-ADAccountasLocalAdministrator.ps1 -Computer '$File' -Trustee ###\###
      any suggestions on the error ### are just where domain and username was
  • How do I read from a text file of servers, and then use that servername in a variable for user
    1 Posts | Last post July 23, 2018
    • How would you read in a file of multiple server names, and then make the trustee for each server be admin_servername_user?
  • how to add users from list
    1 Posts | Last post January 11, 2018
    • I need to modify this script to add a list of users to local Administrators.
      Like so:
      .\Set-ADAccountasLocalAdministrator.ps1 -Computer Server1 -trustee c:\UserList.txt
      How would I replace $Trustee with a text file of usernames, or add a variable to substitute -Trustee with -UserList c:\Users.txt  ?
      Thanks for educating me!
  • not able to add user
    2 Posts | Last post November 29, 2017
    • Hello Jaap,
      Getting below error.
      WARNING: The following exception occurred while retrieving member "add": "The network path was not found. I ran below command only i see different is .ps1 two times on your script.
      .\Set-ADAccountasLocalAdministrator.ps1 -InputFile C:\server\server.txt -Trustee phon\sql
    • You need to enable file and print sharing. I did it via a GPO.
      Computer Configuration > Administrative Templates > Network > Network Connections > Windows Firewall > Domain Profile.
  • Simplify the script for AD account adds ?
    1 Posts | Last post June 23, 2017
    • I am trying to simplify the script if possible but hitting a road block. What i am trying to do is basically have the file on a USB pen drive.  Plug into a Win10 system, run file and have it add a list of predetermined (editable) employee numbers (that are associated with a global domain name) to the local machine as admins. this will give the employees ability to log on, let the machine create the local profile associated with their global accounts.  Thougths or insight is apprciated. 
  • Trying to utilize the script to add a group on multiple serversbut prompting an error please help
    1 Posts | Last post June 08, 2017
    • It is trying to add  the group but after sometime it throws below error, Please help 
      WARNING: Exception calling "add" with "1" argument(s): "A member could not be added to or removed from the local group
      because the member does not exist.
  • Looking to add users to Performance Log Users
    2 Posts | Last post May 19, 2017
    • Thank you for the great help Mr. Brasser
      could you please help to add users on windows performance log users? 
    • Please ignore this one...I can modify AetAccountAsRDPusers.ps1 for performance log users. Thanks!
  • Invalid argument -- Set-ADAccountasLocalAdministrator cmdlet missing
    4 Posts | Last post March 15, 2017
    • .\Set-ADAccountasLocalAdministrator.ps1 : Parameter set cannot be resolved using the specified named parameters.
          + CategoryInfo          : InvalidArgument: (:) [Set-ADAccountasLocalAdministrator.ps1], ParentContainsErrorRecordException
          + FullyQualifiedErrorId : AmbiguousParameterSet,Set-ADAccountasLocalAdministrator.ps1
      What i'm i doing wrong. Similar to Bill77's issue
    • Hi Step2skimo, 
      Can you show which parameters you are using to execute the command? Based on the error message I think you might be using a wrong set of parameters.
      Jaap Brasser
    • Hello Balu, 
      you are receiving that error because you are trying to run the selection without the specified parameters. You need to specify both parameters, Computer and Trustee, or Inputfile and Trustee. If you copy and paste the PS1 data and just run the selection you will get the error you are receiving, since the function isn't defined and there are parameters missing. Here's a working example below, Inputfile being a csv of all servers I want to add the trustee account to.
      .\Set-ADAccountasLocalAdministrator.ps1 -InputFile C:\Users\darivera\Documents\allservers.csv -Trustee Sp_Task_Scheduler
    • hello Jaap,
      many thanks for your response . 
      I was able to successfully use this now.
      This worked for me.
1 - 10 of 52 Items