Search code examples
powershellvbscript

How to remove local admins from machines in a list


Each week I receive a list of computers and one username associated with each computer. I need to remove each particular user from the Administrators group on the associated computer.

Is there a way to script this?


Solution

  • I cannot fully test this, but you should be able to do essentially this:

    Import the list:

    Import-Csv "File.csv" | Foreach-Object {    
     $User= $_.Username    
     $PC = $_.ComputerName
    
     psexec "$PC" net user "$User" /delete 
    }
    

    This assumes you have header columns named Username and ComputerName.