Home Blog How To Add Users to the Local Administrator Group using Powershell

How To Add Users to the Local Administrator Group using Powershell

3
3437

Introduction

Adding users, or most often groups from Active Directory to the local administrator group on the server or client, is a common task carried out as a system administrator.

Previously, accomplishing this required some scripting, but now it’s possible to use a simple one-liner. Of course, you can also use this one-liner in your scripts.

In this blog post, I cover how to add users and groups to the local administrator group usingĀ Powershell. I also cover how to remove them.

How to add users or groups to the local administrator group using Powershell

The local administrator group in Computer Management

The commands for adding or removing a user or group from a local admin group is the same.

Note that all the commands below require that you are running an elevated Powershell window.

Add a domain user to the local administrator group using Powershell

Add-LocalGroupMember -Group "Administrators" -Member "domain\user or group," "additional users or groups."
Add users or groups to the local administrator group using Powershell

Add a local user to the local administrator group using Powershell

When adding a local user to the admin group, use this command:

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

Add a Microsoft account to the local administrator group using Powershell

If you want to add a Microsoft account to the local admin group, use the following command:

Add-LocalGroupMember -Group "Administrators" -Member "MicrosoftAccount\username@domain.com"

Review that the user or group has been added to the local admin group

That’s it! When I look in the local administrator group from the Computer Management view, I now see my domain user:

Domain user has been added to the local administrator group using Powershell

You can also see which users or groups are part of the local admin group using Powershell:

Get-LocalGroupMember -Group "Administrators"

How to remove a user or group from the local admin group using Powershell

If you want to remove a user or group from the local admin group, enter this command:

Remove-LocalGroupMember -Group "Administrators" -Member "the same as for adding a user or group"

Conclusion

Carrying out simple tasks as adding users or groups to the local administrator group can be done via the GUI or Powershell.

I highly recommend using Powershell for tasks like these, as it’s essential to be fluent in Powershell.

If you want to improve your Powershell skills, make sure to sign up for Pluralsight. It’s definitely my favorite way of learning new skills!

How do you add users or groups to the local administrator group? Please leave a comment below!

References

Related posts

3 COMMENTS

  1. one of the things that irritates me to no end when i look at scripts online is the lack of documentation in them.
    for folks that are trying to learn it is nice to know what each function or call is doing within the script.
    It’s also nice when you enclose the usage information within the script documentation, ie what version of Ps you are writing to, etc. that way people hunting for code snippets dont have to read 3/4 of the way down the page only t9o find that this is applicable to windows server 2012 that runs powershell 3.0 or higher..

LEAVE A REPLY

Please enter your comment!
Please enter your name here