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
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...)
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.