strOU = WSCript.Arguments(0) ' DN of the OU enclosed in quotes
' Configure ADODB ADsDSO connection
'
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 3000
' Find the OU
'
objCommand.CommandText = _
";(objectClass=organizationalUnit)" & _
";gpLink,distinguishedName;base"
Set objRecordSet = objCommand.Execute
strGpLinks = objRecordSet.Fields("gpLink").Value
intCnt = 0
' Parse the gpLink
'
Do until strGpLinks = ""
i = instr(strGpLinks,"]")
strGpoDn = mid(strGPlinks,2,i-2) 'DN for LDAP query
strGpLinks = mid(strGPLinks,i+1) 'strip it off the gpLink string
' Use the DN to find the GPO object
'
objCommand.CommandText = "<" & mid(strGpoDn,1,len(strGpoDn)-2) & ">;" & _
"(objectClass=groupPolicyContainer);displayName;base"
set objRecordSet = objCommand.Execute
strGPOName = objRecordSet.Fields("displayName").Value
strGPOGuid = mid(strGpoDn,11,38)
if mid(strGpoDN,len(strGpoDn),1)="0" then
strGpoLinked = "*Linked*"
else
strGpoLinked = "unlinked"
end if
wscript.echo chr(34) & strGPOName & chr(34) & "," & strGpoLinked & "," & strGpoGuid
intCnt = intCnt + 1
Loop
wscript.echo intCnt
|