Add List of Computers to a List of AD Groups

  • 9 April 2017
  • Sean Huggans
Description: 

Add a designated list of computers to a designated list of AD groups.

Language: 
PowerShell
Usage Type: 
Standalone
Script Source: 
###################################################
# Add List of Computers to a List of AD Groups
# Script by Sean Huggans
# Date: 2017.04.09
###################################################
$GroupList = "C:\Temp\GroupList.txt"
$ComputerList = "C:\Temp\PCList.txt"
 
ForEach ($ADGroup in $(Get-Content $GroupList)) {
 echo "======================"
 echo "=  $ADGroup"
 echo "======================"
 ForEach ($ADComputer in $(Get-Content $ComputerList)) {
  Try {
   Add-ADGroupMember -Identity "$($(Get-ADGroup "$ADGroup").DistinguishedName)" -Members "$($(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 as-is, without warranty of any kind whatsoever. visuaFUSION, FMSCUG or any other program listed here's author are not responsible for any damages or shortcomings that result from usage of any of these applications.
Error | visuaFUSION Systems Solutions Blog

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /mnt/home/visuafus/public_html/bahusa.net/includes/common.inc:2861) in drupal_send_headers() (line 1551 of /mnt/home/visuafus/public_html/bahusa.net/includes/bootstrap.inc).
  • Error: Call to undefined function mail() in DefaultMailSystem->mail() (line 79 of /mnt/home/visuafus/public_html/bahusa.net/modules/system/system.mail.inc).

Error

The website encountered an unexpected error. Please try again later.