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.
- Remove-LocalUser
- Remove-LocalGroupMember
- Remove-LocalGroup
1. let us start with removing a user in PowerShell. This is done with the Remove-LocalUser command.
Here's the syntax: Remove -LocalUser -Name “Username”
where Username is the user's account name.
2. What about removing groups in PowerShell? This can also be done through PowerShell using the Remove-LocalGroup command.
The syntax: Remove-LocalGroup -Name “GroupName”
where GroupName is the name of the group.
3. Sometimes we just want to remove a user from a group in PowerShell 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.
https://monovm.com/blog/create-local-user-with-powershell/
https://monovm.com/blog/add-users-to-local-group-with-powershell/
https://monovm.com/blog/creating-local-groups-with-powershell-command/