This article outlines how to get, add and remove users of a local administrator group on SharePoint servers using a PowerShell script.

Local Administrators

The script does the following functionality.

  1. Gets the local administrators of the machine.
  2. Adds a user to the local administrator of the machine (the user must enter the user details into the AddUsers.csv file and place it under the folder where the PowerShell script exists).
  3. Removes a user from the local administrator of the machine (the user must enter the user details into the RemoveUsers.csv file and place it under the folder where the PowerShell script exists).

Get the local administrators of the machine
The following piece of code gets the users under the local administrator group of the machine.


 

Add users to the local administrator of the machine
The following piece of code helps to add the users to the local administrator group on the SharePoint servers.


 

Remove users from local administrator of the machine
The following piece of code helps to remove the users from the local administrator group on the SharePoint servers.


 

Complete Code

Execution Procedure

  1. Download and copy the script folder to the SharePoint server.
  2. Launch the SharePoint management shell.
  3. Navigate to the script path and execute the script.

Enter the desired option.