Copy GPO Links 2.0

  • 17 August 2016
  • Sean Huggans
Description: 

This script is a modified version of Tony Murray's original script located at http://www.open-a-socket.com/index.php/2010/12/02/powershell-script-to-c....

It will loop through the list of distinguished names found in C:\temp\newOUlist.txt (one DN per line), copying the links, link order, enforcements, etc. from the DN set in the $Source variable. The original copying function was Tony's, I simply added the loop, enforcement checking, and functionality to read from a supplied list to make it even more useful in a bulk situation.

Language: 
PowerShell
#########################################################
#
# Name: CopyGPOLinks.ps1
# Original Author: Tony Murray
# Version: 1.0
# Original Date: 26/10/2010
# Comment: PowerShell 2.0 script to copy GPO links from
# one OU to another
#
# Modified by: Sean Huggans
# Added external list function as well as enforcement
# checking, also added human readable output.
#
#########################################################
# Import the Group Policy module
Import-Module GroupPolicy
### Set global variables
# Source for GPO links
$Source = “OU=SampleOU,DC=SampleDomain,DC=org”
 
$TargetList = “c:\temp\newOUlist.txt”
# Target where we want to set the new links
### Finished setting global variables
function CopyGPOs {
# Get the linked GPOs
$linked = (Get-GPInheritance -Target $source).gpolinks
echo “————————————————”
echo $Target
echo “————————————————”
# Loop through each GPO and link it to the target
foreach ($link in $linked)
{
$guid = $link.GPOId
$title = $link.DisplayName
$order = $link.Order
$enabled = $link.Enabled
if ($enabled)
{
$enabled = “Yes”
}
else
{
$enabled = “No”
}
$enforced = $link.Enforced
if ($enforced)
{
$enforced = “Yes”
}
else
{
$enforced = “No”
}
echo “———”
echo$title – Link Enabled: $enabled – Policy Enforced: $enforced# Create the link on the target
New-GPLink -Name $title -Target $Target -LinkEnabled $enabled -confirm:$false
# Set the link order on the target
Set-GPLink -Name $title -Target $Target -Order $order -confirm:$false
# Set the original enforcement setting on the target
Set-GPLink -Name $title -Target $Target -Enforced $enforced -confirm:$false
echo ” ”
}
echo ” ”
}
$DestList = Get-Content $TargetList
foreach ($ListedOU in $DestList) {
$Target = $ListedOU
CopyGPOs
}
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.