Wednesday, July 18, 2007

VBS Script To Enumerate Active Directory OU Names And Paths And Send To Excel - Don Hite

VBS Script To Enumerate Active Directory OU Names And Paths And Send To Excel - Don Hite

VBS Script:

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
intRow = 2

objExcel.Cells(1, 1).Value = "OU Name"
objExcel.Cells(1, 2).Value = "OU Path"

Set objDomain = GetObject("LDAP://RootDSE")
strDomain = objDomain.Get("DefaultNamingContext")

set strOU = GetObject("LDAP://" & strDomain )
strOU.Filter = Array("OrganizationalUnit")

For Each objItem In strOU
arrOU = Split(objItem.Name, "=")
objExcel.Cells(intRow, 1).Value = arrOU(1)
objExcel.Cells(intRow, 2).Value = objItem.AdsPath
intRow = intRow + 1
Next

objExcel.Range("A1:B1").Select
objExcel.Selection.Font.ColorIndex = 11
objExcel.Selection.Font.Bold = True
objExcel.Range("A1:B1").Select
objExcel.Cells.EntireColumn.AutoFit

MsgBox "Done"

No comments: