PowerShell is a tool for system and network administrators with countless usages. One of them is the management of users and groups. throughout this tutorial, you will learn how to remove users or groups through PowerShell commands. Please keep in mind that this tutorial is written based on PowerShell 5.1 and should work with future releases. This version of PowerShell comes pre-installed on Windows 10+ and Windows Server 2016+.
Here are the commands you're going to be using for these tasks.
First. let us start with removing a user. This is done with the Remove-LocalUser command.
Here's the syntax:
Remove -LocalUser -Name “Username” where Username is the user's account name.
What about removing groups? This can also be done through PowerShell using the Remove-LocalGroup command.
Remove-LocalGroup -Name “GroupName” where GroupName is the name of the group.
Sometimes we just want to remove a certain user from a group without completely deleting the user. This is also a task that could be accomplished through PowerShell's cmdlets. The most suitable one for it would be Remove-LocalGroupMember.
The syntax is as follows:
Remove-LocalGroupMember -Group “GroupName” -Member “UserName”
That is all for this tutorial, however, to learn more about PowerShell you can check out our extensive knowledgebase. Along with other PowerShell tutorials, you will also find the latest IT news and informative articles on related topics.