Jump to content

Powershell Copy GPO Links from one GPO. Problem with Variable


Recommended Posts

Posted

Hi there

 

Using the following command

 

Get-ADOrganizationalUnit -LDAPFilter '(gPLink=*{.........-.....-......-.....-..........}*)'

 

I want to be able to define the GUID of the gpo via

 

$GPOGUID = {.........-.....-......-.....-..........}

 

However it doesnt seem to work for me.

 

Script is below. Im creating it to be able to copy gpo links from one gpo to another.

Thanks

Nick

 

 

 

 

 

 

 

 

 

 

 

 

# Command can be used to get GUID

#Get-ADOrganizationalUnit -LDAPFilter '(gPLink=*)'

 

#Enter Destination GPO

$DestinationGPOName = "GPONAME"

 

 

#Enter Guid '(gPLink=*{Enter GUID HERE}*)'

$Info = Get-ADOrganizationalUnit -LDAPFilter '(gPLink=*{.........-.....-......-.....-..........}*)'

 

#Export GPO Links to txt file - Path c:\notes\links.txt

$Info.DistinguishedName > "c:\notes\links.txt"

 

#Import data from path c:\notes\links.txt

$List = Get-Content "c:\notes\links.txt"

 

#Foreach entry in c:\notes\links.txt

Foreach ($Link in $list) {

 

#Add new link to GPO entered at the top

New-GPLink -Name $DestinationGPOName -Target $Link }

Posted (edited)

$GPOGUID = '*{D16A8C8A-0C59-4371-8640-E99E8CCFB726}*'

Get-ADOrganizationalUnit -LDAPFilter "(gPLink=$GPOGUID)"

 

in fact

 

$GPOGUID = '{D16A8C8A-0C59-4371-8640-E99E8CCFB726}'

 

Get-ADOrganizationalUnit -LDAPFilter "(gPLink=*$($GPOGUID)*)"

Edited by HPlum78
  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...