strcsv = "c:\csv.csv"
Set objfso = CreateObject("Scripting.FileSystemObject")
Set objcsv = objfso.CreateTextFile(strCsv, True)
objcsv.WriteLine "cn,description,displayName,dNSHostName,location,machineRole,name,networkAddress,operatingSystem"
strOuname = InputBox("enter ou name")
Set colItems = GetObject(searchad("organizationalUnit", strOuName, "adspath"))
colItems.Filter = Array("Computer")
For Each objItem In colItems
objcsv.WriteLine objItem.CN & "," & objItem.description & "," & objItem.displayName & "," & objItem.dNSHostName & "," & objItem.location & "," & objItem.machineRole & "," & objItem.name & "," & objItem.networkAddress & "," & objItem.operatingSystem
Next
Function SearchAd(objtype, objname, strProp)
Set objRootDSE = GetObject("LDAP://RootDSE")
strDomain = "LDAP://" & objRootDSE.Get("defaultNamingContext")
Set oCn = CreateObject("ADODB.Connection")
Set oCmd = CreateObject("ADODB.Command")
oCn.Provider = "ADsDSOObject"
oCn.Open "Active Directory Provider"
Set oCmd.ActiveConnection = oCn
oCmd.Properties("Page Size") = 1000
oCmd.Properties("Searchscope") = 2
oCmd.CommandText = "SELECT " & strProp & " FROM '" & strDomain & "' WHERE objectCategory='" & objtype & "' and name='" & objname & "' ORDER BY Name"
Set oRS = oCmd.Execute
'oRS.MoveFirst
Do Until oRS.EOF
SearchAd = oRS.Fields(strProp).Value
oRS.MoveNext
Loop
End Function
|