GPO link help...please

G

Guest

Hello !

I have found the following script that adds a GPO link for a policy named
"SitePolicy" defined in "Default-first -site-name" to a second site in
Windows 2000 infrastructure.
I have multiple sites and I don't know how to modify this script - for
adding this "Site Policy" link to EVERY SITE in
cn=sites,cn=configuration,dc=test,dc=com whithout applying again this GPO
link for the original "Default first site name" where is defined the
original "Site Policy" and also without applying for the objects cn=Subnets
and cn=Inter-Site-Transports in the cn=sites,cn=configuration,dc=test,dc=com
..This two objects are objects which are not sites .


Please if you could help me,,,
Thank You in advance

On Error Resume Next
Set objContainer = GetObject _
("LDAP://cn=secondsite,cn=sites,cn=configuration,dc=test,dc=com ")

strExistingGPLink = objContainer.Get("gPLink")

strGPODisplayName = "SitePolicy"
strGPOLinkOptions = 2
strNewGPLink = "[" & GetGPOADsPath & ";" & strGPOLinkOptions & "]"

objContainer.Put "gPLink", strExistingGPLink & strNewGPLink
objContainer.Put "gPOptions", "0"

objContainer.SetInfo

Function GetGPOADsPath
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

objCommand.CommandText = _
"<LDAP://cn=Policies,cn=System,dc=test,dc=com>;;" & _
"distinguishedName,displayName;onelevel"
Set objRecordSet = objCommand.Execute

While Not objRecordSet.EOF
If objRecordSet.Fields("displayName") = strGPODisplayName Then
GetGPOADsPath = "LDAP://" & objRecordSet.Fields("distinguishedName")
objConnection.Close
Exit Function
End If
objRecordSet.MoveNext
Wend
objConnection.Close
End Function
 
A

Andrei Ungureanu

try this script that will enumerate all the AD sites:

Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get("configurationNamingContext")

strSitesContainer = "LDAP://cn=Sites," & strConfigurationNC
Set objSitesContainer = GetObject(strSitesContainer)
objSitesContainer.Filter = Array("site")

For Each objSite In objSitesContainer
'here enter your code for linking a gpo
Next
 
A

Andrei Ungureanu

also look at the last script from this page
http://www.windowsitpro.com/Articles/Print.cfm?ArticleID=39856
you'll need GPMC installed to be able to run that script.


--
Andrei Ungureanu
www.eventid.net
Free Windows event logs reports
http://www.altairtech.ca/evlog/

Andrei Ungureanu said:
try this script that will enumerate all the AD sites:

Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get("configurationNamingContext")

strSitesContainer = "LDAP://cn=Sites," & strConfigurationNC
Set objSitesContainer = GetObject(strSitesContainer)
objSitesContainer.Filter = Array("site")

For Each objSite In objSitesContainer
'here enter your code for linking a gpo
Next


--
Andrei Ungureanu
www.eventid.net
Free Windows event logs reports
http://www.altairtech.ca/evlog/

anonymous said:
Hello !

I have found the following script that adds a GPO link for a policy
named
"SitePolicy" defined in "Default-first -site-name" to a second site in
Windows 2000 infrastructure.
I have multiple sites and I don't know how to modify this script - for
adding this "Site Policy" link to EVERY SITE in
cn=sites,cn=configuration,dc=test,dc=com whithout applying again this GPO
link for the original "Default first site name" where is defined the
original "Site Policy" and also without applying for the objects
cn=Subnets
and cn=Inter-Site-Transports in the
cn=sites,cn=configuration,dc=test,dc=com
.This two objects are objects which are not sites .


Please if you could help me,,,
Thank You in advance

On Error Resume Next
Set objContainer = GetObject _
("LDAP://cn=secondsite,cn=sites,cn=configuration,dc=test,dc=com ")

strExistingGPLink = objContainer.Get("gPLink")

strGPODisplayName = "SitePolicy"
strGPOLinkOptions = 2
strNewGPLink = "[" & GetGPOADsPath & ";" & strGPOLinkOptions & "]"

objContainer.Put "gPLink", strExistingGPLink & strNewGPLink
objContainer.Put "gPOptions", "0"

objContainer.SetInfo

Function GetGPOADsPath
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

objCommand.CommandText = _
"<LDAP://cn=Policies,cn=System,dc=test,dc=com>;;" & _
"distinguishedName,displayName;onelevel"
Set objRecordSet = objCommand.Execute

While Not objRecordSet.EOF
If objRecordSet.Fields("displayName") = strGPODisplayName Then
GetGPOADsPath = "LDAP://" & objRecordSet.Fields("distinguishedName")
objConnection.Close
Exit Function
End If
objRecordSet.MoveNext
Wend
objConnection.Close
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top