Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to link an existing to a new OU (that was just created), using the resources found here: http://support.microsoft.com/kb/248392 and here: http://www.thescriptlibrary.com/default.asp?Action=Display&Level=Category3&ScriptLanguage=VBScript&Category1=Active%20Directory&Category2=OUs&Title=Assign%20a%20New%20Group%20Policy%20Link%20to%20an%20OU,%20revised

The problem is that when it does .Get("gPLink") it gives an error that says "The directory property cannot be found in the cache". I am fairly positive this is due to the fact that there are no GPO's currently linked to the OU, and it expects at least one (correct me if I'm wrong).

Would appreciate any hints and tips! Thanks

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Without seeing your script I'd say that your hypothesis is reasonable. The error you're seeing should be thrown on the line of your script where you ".Get" the "gpLink" property. Put some error trapping around that line and you should be fine. The first script you link to has such error trapping (albeit in the sloppy form of an "On Error Resume Next" high in the script rather than a nice error handler at the point where the error could occur).

Edit:

Here's a "remix" of the script you linked to at Microsoft with some error handling around the ".Get" I talked about. When the "gPLink" attribute isn't specified the ".Get" would cause the error you're seeing so trapping it with the "On Error Goto" end-runs the error. (I really should be checking what error is returned and acting appropriately for the error returned...)

Option Explicit
Dim objiADSToolsDCFunctions, objOU, objGPOs, gPLink, i, gPOChosen

Const DNS_DOMAIN_NAME = "domain.com"
Const OU_DN = "ou=test,dc=domain,dc=com"

Set objiADSToolsDCFunctions = CreateObject("iadstools.dcfunctions")
Set objOU = GetObject("LDAP://" & DNS_DOMAIN_NAME & "/" & OU_DN)

objGPOs = objiADSToolsDCFunctions.GetGPOs("flounderball.gov","home-srv01")

If objGPOs > 0 Then
    For i = 1 to objGPOs
        WScript.Echo objiADSToolsDCFunctions.gponame(i)
        WScript.Echo Chr(9) & objiADSToolsDCFunctions.gpoguid(i)
    Next ' i

    WScript.Echo "The objOU you will be modifying is:"
    WScript.Echo Chr(9) & objOU.adspath

    gPOChosen = InputBox("Enter the name of the GPO to add (case insensitive):")

    If gPOChosen <> "" Then
        For i = 1 to objGPOs
            If LCase(objiADSToolsDCFunctions.gPOName(i)) = LCase(gPOChosen) Then
                On Error Resume Next
                gPLink = objOU.Get("gPLink")
                On Error Goto 0

                gPLink = gPLink & "[LDAP://CN=" & objiADSToolsDCFunctions.gPOGUID(i) & ",CN=Policies,CN=System," & objiADSToolsDCFunctions.getdefaultnamingcontext(DNS_DOMAIN_NAME) & ";0]"

                objOU.Put "gpLink", gpLink
                objOU.SetInfo

                WScript.Echo "Successfully added a link to this objOU for the GPO (" & objiADSToolsDCFunctions.gponame(i) & ")"
                Exit For
            End If
        Next ' i
    End If
End If
share|improve this answer
    
Thanks for the answer, but could you give an example on how to do this? I tried to differentiate between an empty var and one that had existing GPOs in it, but that didn't work. I'm unsure how to go about this one... –  HannesFostie Jul 4 '11 at 12:57
    
This seems to have done the job, thanks a lot for the edit! –  HannesFostie Jul 6 '11 at 6:30

Your error message states that the property isn't loaded into the object's cache. So why don't you try explicitly adding it to the object's cache with the GetInfoEx method?

Just before your objContainer.Get("gPLink") line, put the following:

objContainer.GetInfoEx Array("gPLink"), 0

This doesn't seem to be necessary in my domain environment. But who knows how yours differs from mine. Also, when I run my sample script against an OU that doesn't have any GPO's attached, the strExistingGPLink just gets set to an empty string.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.