Powershell script. Remove all the local admin users from a CSV

FUENTES Jose 21 Reputation points
2022-08-08T10:02:41.957+00:00

I have a CSV file with all users I want to delete from the administrator local group. So for instance, in one workstation, in the local administrator group has three users (Jose, Mary, Anna) and in the CSV file has Jose and Mary, in the local administrator group after launching the script should be only Anna. I hope I explain properly

I've done this script in PowerShell, but doesn't work.

Import-Csv -path "C:\Temp\Files\Users.csv" | ForEach-Object {Remove-localgroupmember -Identity "Administrators" -Members $_.'Account' -Confirm:$false}

Please anybody helps me??

Windows for business Windows Server User experience PowerShell
{count} votes

Accepted answer
  1. Andreas Baumgarten 123.4K Reputation points MVP Volunteer Moderator
    2022-09-28T16:35:51.343+00:00

    Hi @FUENTES Jose ,

    thanks for the feedback.

    Does the answer help to solve the issue?
    If you found the answer helpful, it would be great if you please mark it "Accept as answer". This will help others to find answers in Q&A

    ----------

    Regards
    Andreas Baumgarten

    0 comments No comments

18 additional answers

Sort by: Most helpful
  1. Andreas Baumgarten 123.4K Reputation points MVP Volunteer Moderator
    2022-09-22T14:09:52.817+00:00

    Acceso denegado. in English is Access denied. ?

    If so your current user is not allowed to remove the user from the local group.

    Please run the command from an elevated PowerShell with Admin-Permission.

    ----------

    (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

  2. FUENTES Jose 21 Reputation points
    2022-09-28T16:11:37.843+00:00

    It worked!!!
    Thank you so much


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.