Disable or Remove the domain user "Remote Desktop User" from localgroup member with Powershell

PerserPolis-1732 1,576 Reputation points
2022-02-11T07:40:33.88+00:00

Hi,

I added manually on the "computer Management" --->Local Users and Groups--->Groups--->Remote Desktop Users, an domain user on many machines.
Now I want to remove it with PowerShell Script and deploy it to all machines.

I can do it with:

Remove-LocalGroupMember -Group “Remote Desktop Users” -Member “username”

OR

net localgroup “Remote Desktop Users” “username” /delete

I have to put manually the "username"

How can I put with a variable or file?

Regards

Windows Server 2016
Windows Server 2016
A Microsoft server operating system that supports enterprise-level management updated to data storage.
2,436 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,635 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,462 questions
{count} votes

Accepted answer
  1. Andreas Baumgarten 104K Reputation points MVP
    2022-02-11T23:36:47.453+00:00

    Hi @PerserPolis-1732 ,

    you can try this:

    $users = "Peter", "Paul", "Marry"  
    $localGroup = "Remote Desktop Users"  
    $users | ForEach-Object {  
      Remove-LocalGroupMember -Group $localGroup -Member $_  
    }  
    

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments

0 additional answers

Sort by: Most helpful