Link GPO to All Computer OUs

  • 20 September 2016
  • Sean Huggans
Description: 

In environments that have several computer OUs, the following script can save you from manually linking a GPO several times. The "computer" keyword could be switched out for any other OU name you want - just remember it will link to any and all OUs named that string.

Language: 
PowerShell
###############################
# LinkGPOtoAllComputerOUs
# Script by Sean Huggans
# Original Date: 2016.09.14
###############################
 
Import-Module ActiveDirectory
Import-Module GroupPolicy
 
foreach ($ComputerOU in $(Get-ADOrganizationalUnit -Filter 'Name -eq "Computers"' | Sort)) {
New-GPLink -Name "<GPONAME>" -Target $ComputerOU -LinkEnabled "Yes" -confirm:$false
echo $ComputerOU.DistinguishedName
}
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.