Remove List of Computers from a List of AD Groups

  • 12 December 2016
  • Sean Huggans
Description: 

Removes a designated list of computers from a designated list of AD groups.

Language: 
PowerShell
###################################################
# Remove List of Computers from List of AD Groups
# Script by Sean Huggans
# Date: 2016.12.12
###################################################
$GroupList = "C:\Temp\GroupList.txt"
$ComputerList = "C:\Temp\ComputerList.txt"
 
ForEach ($ADGroup in $(Get-Content $GroupList)) {
 echo "======================"
 echo "=  $ADGroup"
 echo "======================"
 ForEach ($ADComputer in $(Get-Content $ComputerList)) {
  Try {
   Remove-ADGroupMember -Identity $(Get-ADGroup $ADGroup).DistinguishedName -Member $(Get-ADComputer $ADComputer).DistinguishedName -Confirm:$false
   echo "$ADComputer"
  } catch {
   echo "Error.  Verify Computer and Group Names."
  } finally {
  }
 }
}
Note: that all applications posted here are posted for use, both commercial and non-commercial, free of charge, and as such are provided without warranty of any kind whatsoever. FMSCUG or any program's author are not responsible for any damages or shortcomings that result from usage of any of these applications.