Powershell script for creating copy of GPOs

jay k 21 Reputation points
2021-06-23T07:39:17.733+00:00

Team, could you please help with the script to copy the existing GPOs and create a copy of the GPO with PowerShell script for creating copy of the multiple GPOs for testing

Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
4,740 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,362 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Leon Laude 85,651 Reputation points
    2021-06-23T08:42:50.127+00:00

    Hi @jay k ,

    You can accomplish this by using the Copy-GPO PowerShell cmdlet, here's a couple of examples on how to copy a Group Policy with PowerShell:

    Copy one GPO

    Copy-GPO -SourceName "TestGpo1" -SourceDomain "test.contoso.com" TargetName "TestGpo1" -TargetDomain "sales.contoso.com"  
    

    Copy all GPOs

    Get-GPO -All -Domain "sales1.contoso.com" | ForEach-Object {$_ | Copy-GPO -TargetName ($_.DisplayName) -TargetDomain "sales2.contoso.com" -CopyAcl -MigrationTable "C:\Temp\tables\MigrationTable.migtable"}  
    

    ----------

    If the reply was helpful please don't forget to upvote and/or accept as answer, thank you!

    Best regards,
    Leon


  2. Ian Xue (Shanghai Wicresoft Co., Ltd.) 29,571 Reputation points Microsoft Vendor
    2021-06-24T01:44:37.117+00:00

    Hi,

    You can link the GPO to a specified OU using the New-GPLink cmdlet.

    $sourceGPO = "TestGPO"  
    $targetGPO = "test_productionGPOname"  
    $ou = "OU=test, DC=contoso, DC=com"  
    Copy-GPO -SourceName $sourceGPO -TargetName $targetGPO  
    New-GPlink -Name $targetGPO -target $ou -LinkEnabled Yes  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments