Question : VBscript Help for a Newbie trying to pull AD Computer Info into Excel 2007

All,

     Can someone please help me.  I need to pull Computer info (Netbios name, account status, OU, etc) from AD.  I'm told the best way to do this is through a VBScript.  Is there a generic script I can use; I know VERY little scripting.  Thanks SOOO Much!!!!

Answer : VBscript Help for a Newbie trying to pull AD Computer Info into Excel 2007

hey

my script still not vba but it more Suitable to your needs
it will ask you for the ou name and export the computers info in the ou to csv file
that you can open directly with excel and do what ever you want


paste the code to notepad and save it with vbs extension
edit line 1 for your csv file name and path

if you need any adjust to the script let me know.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
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
Random Solutions  
 
programming4us programming4us