Link List of GPOs to List of OUs

  • 30 November 2016
  • Sean Huggans
Description: 

Wrote this while needing to list the same set of GPOs to many OUs.

Language: 
PowerShell
#########################################################
#
# Name: LinkGPOs.ps1
# Author: Sean Huggans
# Version: 1.0
# Date: 2016.11.30
# Links GPOs provided in a supplied list to OUs provided
# in a supplied list.
#
#########################################################
Import-Module GroupPolicy
 
$TargetList = “c:\temp\OUlist.txt”
$GPOList = "c:\temp\gpolist.txt"
 
function LinkGPO {
echo $ListedOU
# Create the link on the target
New-GPLink -Name $title -Target $ListedOU -LinkEnabled "Yes" -confirm:$false
# Set the link order on the target
Set-GPLink -Name $title -Target $ListedOU -Order 1 -confirm:$false
# Set the original enforcement setting on the target
Set-GPLink -Name $title -Target $ListedOU -Enforced "No" -confirm:$false
}
 
foreach ($ListedOU in $(Get-Content $TargetList)) {
 echo “————————————————-----------------------------echo $ListedOU
 echo “———————————————-----------------------------—”
 ForEach ($title in $(Get-Content $GPOList)) {
  echo $title
  LinkGPO
  echo "---"
 }
 echo ” ”
}
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.