How to remove bulk user local admin right wirh Powershell

Wu Yuki 81 Reputation points
2021-05-12T04:38:43.917+00:00

Hello ,

anyone know how to remove bulk user 's local admin right with PowerShell script?

One alternative I think is to use "Net localgroup" to create a batch file and add it to user logon scriptpath to delete the local admin right when user login pc.

if possible to meet the target by Powershell script pls ? Thanks for you sharing in advance.

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,576 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ian Xue 38,551 Reputation points Microsoft Vendor
    2021-05-13T06:12:37.277+00:00

    Hi,

    Since Get-localgroupmember -Group "administrators" returns only local users, there are no domain users or groups in your local administrators group. You have to run your script as administrator or you'll see the "Access denied" error.

    If you want to run Remove-LocalGroupMember on remote computers, you can try Invoke-Command like below

    $userlist=import-csv 'D:\powershell  test\testremove.CSV'  
    Invoke-Command -ComputerName $computer -ScriptBlock{ Remove-LocalGroupMember -Group administrators -Member $using:userlist.samaccountname } -Credential ''  
    

    Before using Invoke-Command to run commands on a remote computer, read about_Remote.

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Ian Xue 38,551 Reputation points Microsoft Vendor
    2021-05-12T06:18:07.193+00:00

    Hi,

    You can use the Remove-LocalGroupMember cmdlet in PowerShell.

    Remove-LocalGroupMember -Group administrators -Member $users  
    

    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.localaccounts/remove-localgroupmember#examples

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.