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
Usage Type: 
Standalone
Script Source: 
#########################################################
#
# 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 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.