question

PerserPolis-1732 avatar image
0 Votes"
PerserPolis-1732 asked NewbieJones-6218 edited

Need script to remove AD user/group from local admins group on different client machines or systems

Hi,

I want to remove the AD User from local Amin group on the client machine. with power shell script.

Get-LocalGroupMember -Group 'Administrators' | Where {$_.objectclass -like 'User'} | Remove-LocalGroupMember Administrators

or

$remote-comp = 'test1'
Invoke-Command -ComputerName $remote-comp -ScriptBlock {
Get-LocalGroupMember -Group 'Administrators' | Where {$_.objectclass -like 'User'} | Remove-LocalGroupMember Administrators


But I have 100 AD Users on 100 different client machine.

Is there any way to do that in one step? for example with a CSV file?

Regards

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

NewbieJones-6218 avatar image
0 Votes"
NewbieJones-6218 answered NewbieJones-6218 edited

Something like...

 $computers  = "test1","test2" 
 # or $computers = IMPORT-CSV $inputfile
    
 ForEach ($computer in $computers) {
     Invoke-Command -ComputerName $computer -ScriptBlock {
     # or $computer.Name (the most appropriate field header in the CSV)
         Get-LocalGroupMember -Group 'Administrators' | 
             Where-Object {$_.objectclass -like 'User'} | 
                 Remove-LocalGroupMember Administrators
     }
  }
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.