# Script to change a non-admin user to an admin user in Windows

A user belonging to the ‘Users’ group does not have complete access to the device. Suppose you want to enable administrator privileges for a user. You can easily get it done by writing commands to remove the users from the ‘Users’ group and add them to the ‘Administrators’ group. These commands can be embedded in a script, and you can run them directly from Hexnode using the [Execute Custom Scripts](https://www.hexnode.com/mobile-device-management/help/executing-custom-scripts-for-windows/) action.

 Note: 
**Supported Versions**:

The scripts given below will be supported on the following versions:

- Windows 10 v1607+ (Pro, Enterprise, Education)
- Windows 11 (Pro, Enterprise, Education)

 

 Disclaimer: 
The sample scripts provided below are adapted from third-party open-source sites.

 

Batch script to change a non-admin user to an admin user 
---------------------------------------------------------

Batch file script to change a non-admin user to an admin user

Rem Step 1: Add the user to the Administrators group. NET LOCALGROUP Administrators Username /ADD Rem Step 2: Remove the user from the Users group NET LOCALGROUP Users Username /DELETE Rem Step 3 (Optional): List the users belonging to Administrators or Users group NET LOCALGROUP Groupname

   1

2

3

4

5

6

7

8

9

10

11

  Rem Step 1: Add the user to the Administrators group.

NET LOCALGROUP Administrators Username /ADD 

Rem Step 2: Remove the user from the Users group 

NET LOCALGROUP Users Username /DELETE 

Rem Step 3 (Optional): List the users belonging to Administrators or Users group 

NET LOCALGROUP Groupname

   

 

  

Replace the terms “Username” and “Groupname” with the actual names.

Batch script to change a non-admin Azure domain account user to an admin user
-----------------------------------------------------------------------------

###  To grant admin rights:

Script to provide admin right to Azure AD accounts

@echo off net localgroup administrators "AzureAD\\SAMName" /add echo. 

   1

2

3

  @echo off 

net localgroup administrators "AzureAD\\SAMName" /add 

echo. 

   

 

  

### To revoke admin rights:

Script to revoke admin rights from Azure AD accounts

@echo off net localgroup administrators "AzureAD\\SAMName" /delete echo. 

   1

2

3

  @echo off 

net localgroup administrators "AzureAD\\SAMName" /delete 

echo. 

   

 

  

Replace SAMName with the username of the Azure domain account.

PowerShell script to change a non-admin user to an admin user 
--------------------------------------------------------------

PowerShell script to change a non-admin user to an admin user

\# Replace 'username' with the actual account name Add-LocalGroupMember -Group "Administrators" -Member "username" # Optional: Verify that the user is now in the Administrators group Get-LocalGroupMember -Group "Administrators"

   1

2

3

4

5

  \# Replace 'username' with the actual account name

Add-LocalGroupMember -Group "Administrators" -Member "username"

\# Optional: Verify that the user is now in the Administrators group

Get-LocalGroupMember -Group "Administrators"

   

 

  

![Action History tab confirms the successful execution of the script to change a non-admin user to an admin user on Windows.](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2022/01/Standard-user-changed-to-administrator-using-script-to-change-non-admin-user-on-Windows--300x150.png)

How to View Script Output in Hexnode
------------------------------------

To review the execution results, navigate to the **Action History** tab of the specific device in your Hexnode UEM portal. Locate the script entry in the **Subject** column and click the **Show Output** button next to the status field to view the returned data.

 Notes:- It is recommended to manually validate the script execution on a system before executing the action in bulk.
- Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.