This message was deleted.
# _general
s
This message was deleted.
m
I have to set up a test OU with inheritance blocked and copy all the GPOs above it back at that level and edit them.
and there are 30 of them, otherwise I’d do it manually
b
do you need links to the same OUs or separate but equal copies of the GPOs?
m
the latter
b
Because you could back them up from the gp console, and then restore them with a different name, then link them to the desired OU.
m
that could work
w
That is my recommendation. Backup, create new GPO, and import settings
j
Could you not just use copy-gpo? Native powershell - get gpo and then copy gpo... get-gpo, copy-gpo, new-gplink
m
probably, if I knew powershell
j
Copy code
$SourceOU = "OU=Workers,OU=Citrix FMA,DC=Kindo,DC=com" # Set DN of your source OU
$DestinationOU = "OU=GPO Test,DC=Kindo,DC=com" # Set DN of your Destination OU


$SourceGPOS = Get-ADOrganizationalUnit -Filter { Distinguishedname -eq $SourceOU } | Select-Object -Property *, @{
    label      = 'FriendlyGPODisplayName'
    expression = { $_.LinkedGroupPolicyObjects | ForEach-Object { ([adsi]"LDAP://$_").displayName -join '' }
    }
}

$SourceGPOS = $SourceGPOS.FriendlyGPODisplayName

foreach ($GPO in $SourceGPOS) {
    $NewGPOName = $GPO + "_Copy" #Source Name plus Identifier
    Copy-GPO -SourceName $GPO -TargetName $NewGPOName -CopyAcl -Verbose
    New-GPLink -Name $NewGPOName -Target $DestinationOU -LinkEnabled Yes -Verbose
}
👍 1
@Mike Streetz (O_P) above should work, hacked it together and tested - Change your Source and Destination OU, alter your new name as required, by default it will copy existing name, and append with a "_Copy"
👏🏻 3
m
I’ll try this out today, thanks man!
🤘 1
I finally tried this out, how do you get it to copy all the linked GPO, not just the ones linked directly to the source OU
j
Lost me a little - do you mean further up the OU structure from the source OU? As in parent OU with policies linked there also?
m
yeah, using Get-GPInheritance instead should work, I’m just not sure how to edit what you’ve got
(Get-GPInheritance -Target $SourceOU).InheritedGpoLinks | select-object DisplayName
that gives me the friendly name
ok, I created the copies but couldn’t get them linked in the same step
(Get-GPInheritance -Target $SourceOU).InheritedGpoLinks | ForEach-Object {Copy-GPO -SourceGuid ($_.GpoId) -TargetName ($_.DisplayName + “_Copy”) -CopyAcl -Verbose}
j
you will need to wrap in a new-gplink for each of them as well
m
I’m still learning powershell, I couldn’t figure that bit out, so just sorted GPO by date and dragged them all to the OU 😛
j
send me what you have and ill take a quick look 🙂
m
that's as far as I got. I tried putting the new-gplink after that but it complained that I didn't have the pipe correct
j
Copy code
# Use this for only the OU's those defined on the Source OU

$SourceOU = "OU=Workers,OU=Citrix FMA,DC=Kindo,DC=com" # Set DN of your source OU
$DestinationOU = "OU=GPO Test,DC=Kindo,DC=com" # Set DN of your Destination OU


$SourceGPOS = Get-ADOrganizationalUnit -Filter { Distinguishedname -eq $SourceOU } | Select-Object -Property *, @{
    label      = 'FriendlyGPODisplayName'
    expression = { $_.LinkedGroupPolicyObjects | ForEach-Object { ([adsi]"LDAP://$_").displayName -join '' }
    }
}

$SourceGPOS = $SourceGPOS.FriendlyGPODisplayName

foreach ($GPO in $SourceGPOS) {
    $NewGPOName = $GPO + "_Copy" #Source Name plus Identifier
    Copy-GPO -SourceName $GPO -TargetName $NewGPOName -CopyAcl -Verbose
    New-GPLink -Name $NewGPOName -Target $DestinationOU -LinkEnabled Yes -Verbose
}


# Use this for All inherited OU's including those defined on the Source OU

$SourceOU = "OU=Workers,OU=Citrix FMA,DC=Kindo,DC=com" # Set DN of your source OU
$DestinationOU = "OU=GPO Test,DC=Kindo,DC=com" # Set DN of your Destination OU

$InheritedGPOS = (Get-GPInheritance -Target $SourceOU).InheritedGpoLinks.DisplayName

foreach ($GPO in $InheritedGPOS) {
    $NewGPOName = $GPO + "_Copy" #Source Name plus Identifier
    Copy-GPO -SourceName $GPO -TargetName $NewGPOName -CopyAcl -Verbose
    New-GPLink -Name $NewGPOName -Target $DestinationOU -LinkEnabled Yes -Verbose
}
two options in there - choose your poison - first one will just copy the scoped GPO's from the source OU, if you want to do the Scoped + Inherited, use the second portion of the code only (it includes the scoped anyway...) there is no error checking, nor does it look for duplicates or validate if things are enabled or not on the source - easy enough to add in, but going to play with my kids for now - let me know if you want it more robust
m
that's awesome, thanks!
👍 1