Thanks you to everyone whe posted a response here. I found an easy (albeit sloppy) way to get what I wanted. I am not currently comfortable with the ADSI stuff and discovered I would have to re-write the whole script to get my data.
If you find an easier way to do this, please let me know:
Option Explicit
'==========================================================================
'
' NAME: User Information.vbs
' DATE: 1-24-03
' REVISED: 1-27-05
'
' AUTHOR: David Schmitt, MCSE
'
' COMMENT: This script queries an OU in an Active Directory structure.
' It gathers user home and profile directory location and size information
' and stores the results into an Excel spreadsheet.
'
' This script was created using ggroups.vbs as a base.
'
'==========================================================================
'integer
Dim intIndex, intGroup, intTotUsersOU, intTotEmpty, intStringLen, _
ii, intTotOverGB, intTotOverMB, intTotOU, intTotUsers, intTotSpaceUsed, _
intTotSpaceUsed2, intTotOverMB2, intTotOverGB2, intTotEmpty2, intFormatMB, _
intFormatGB, intFormatGB2, intFormatMB2
' object
Dim FSO, objXL, xlWrkBk, xlSheet, WSHShell, objHomeDIR, objProfDIR, objSubOU, _
objOU, objUsr
'string
Dim strOUName, strScriptPath, strServer, strGroupDesc, strDept, _
strGroupId, strDomain, strDName, strDisabled, strLocked, strSAM, _
strHomeDIR, strHomeDIRSize, strProfDIR, strProfDIRSize, strOUNames, _
strNames, strDomain1, strDomain2, strDomain3, strDomain4
Public Const xlThin = 2
Public Const xlMedium = -4138
Public Const xlHairline = 1
Public Const xlRight = -4152
Public Const xlLeft = -4131
Public Const xlLandscape = 2
Public Const xlThick = 4
Public Const xlEdgeBottom = 9
Public Const xlEdgeLeft = 7
Public Const xlEdgeRight = 10
Public Const xlEdgeTop = 8
Public Const xlBottom = -4107
Public Const xlDescending = 2
Public Const xlAscending = 1
Public Const OpenFileForReading = 1
Public Const OpenFileForWriting = 2
Public Const OpenFileForAppending = 8
Public Const xlUnderlineStyleSingle = 2
strDomain = "dc=<yourdomain>,dc=com"
strDomain1 = "ou=Disabled,ou=Accounts,dc=<yourdomain>,dc=com"
strDomain2 = "ou=Test,ou=Accounts,dc=<yourdomain>,dc=com"
strDomain3 = "ou=Contractor,ou=Users,ou=Accounts,dc=<yourdomain>,dc=com"
strDomain4 = "ou=Employee,ou=Users,ou=Accounts,dc=<yourdomain>,dc=com"
strServer = "<yourserver>"
'
' Set all counters to zero
'
intTotOU = 0
intTotUsers = 0
intTotEmpty = 0
intTotOverGB = 0
intTotOverMB = 0
intTotSpaceUsed = 0
intTotEmpty2 = 0
intTotOverGB2 = 0
intTotOverMB2 = 0
intTotSpaceUsed2 = 0
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set objXL = WScript.CreateObject("Excel.Application")
Set xlWrkBk = objXL.Workbooks.Add
Set xlSheet = xlWrkBk.ActiveSheet 'Sheet 1
Set FSO = Wscript.CreateObject("scripting.FileSystemObject")
'
' Start formatting the Excel spreadsheet
'
xlSheet.Name="Users"
objXL.Visible = True
intStringLen = Len(Wscript.ScriptFullName) - Len(Wscript.ScriptName)
strScriptPath = Left(Wscript.ScriptFullName, intStringLen)
xlSheet.PageSetup.PrintArea = ""
With xlSheet.PageSetup
.PrintTitleRows = "$1:$3"
'
' Change the Application object: i.e. Application.InchesToPoints to objXL.InchesToPoints
'
.LeftMargin = objXL.InchesToPoints(0.32)
.RightMargin = objXL.InchesToPoints(0.38)
.TopMargin = objXL.InchesToPoints(0.17)
.BottomMargin = objXL.InchesToPoints(0.17)
.HeaderMargin = objXL.InchesToPoints(0.17)
.FooterMargin = objXL.InchesToPoints(0.17)
.Orientation = xlLandscape
.Zoom = 80
.PrintGridlines = True
End With
'
' Format the spreadsheet headers
'
With xlSheet
.Columns(1).ColumnWidth = 21.14
.Columns(2).ColumnWidth = 23.71
.Columns(3).ColumnWidth = 21.57
.Columns(4).ColumnWidth = 19.29
.Columns(5).ColumnWidth = 26.57
.Columns(6).ColumnWidth = 20.29
.Columns(7).ColumnWidth = 37.00
.Cells(1, 1).Value = "Domain"
.Cells(2, 1).Value = strDomain
.Cells(1, 3).Value = "Server"
.Cells(2, 3).Value = strServer
.Cells(1, 7).Value = "Date"
.Cells(2, 7).Value = ("'" & Now())
.Cells(2, 7).NumberFormat = "m/d/yyyy h:mm AM/PM"
.Cells(3, 1).Value = "Account Status"
.Cells(3, 2).Value = "User Name"
.Cells(3, 3).Value = "Home Directory"
.Cells(3, 4).Value = "Home Dir Size"
.Cells(3, 5).Value = "Profile Directory"
.Cells(3, 6).Value = "Profile Dir Size"
.Cells(3, 7).Value = "Group"
End With
With xlSheet.Range("A1:G1")
.Borders(xlEdgeBottom).Weight = xlThick
.Font.Bold = True
.Font.Size = 12
.Interior.ColorIndex = 5
.Interior.Pattern = 1 'xlSolid
.Font.ColorIndex = 2
.Borders.Weight = xlThick
End With
With xlSheet.Range("A2:G2")
.Borders(xlEdgeBottom).Weight = xlThick
.Font.Bold = True
.Font.Size = 10
.Interior.ColorIndex = 14
.Interior.Pattern = 1 'xlSolid
.Font.ColorIndex = 2
.Borders.Weight = xlThick
End With
With xlSheet.Range("A3:G3")
.Borders(xlEdgeBottom).Weight = xlThick
.Font.Bold = True
.Font.Size = 14
.Interior.ColorIndex = 5
.Interior.Pattern = 1 'xlSolid
.Font.ColorIndex = 2
.Borders.Weight = xlThick
End With
xlSheet.Range("B:B").HorizontalAlignment = xlLeft
'
' intIndex equals the number of cells to count down before writing data
' Data starts being written at A4, or (intIndex, 1)
'
intIndex = 4
xlWrkBk.SaveAs(strScriptPath & "User Information_" & Month(Date()) & Day(Date()) & Year(Date()) & ".xls")
'
' Places the collected data into the right cells and formats it
'
Sub ProcessEachUserShort(strDName, strSAM, strDisabled, strLocked)
If strDisabled = True Then
xlSheet.Cells(intIndex, 1).Value = "DISABLED"
Else If strLocked = True Then
xlSheet.Cells(intIndex, 1).Value = "LOCKED"
Else
xlSheet.Cells(intIndex, 1).Value = ""
End If
End If
With xlSheet.Cells(intIndex, 1)
.Font.Colorindex = 3
.Font.Size = 8
.HorizontalAlignment = xlRight
End With
xlSheet.Cells(intIndex, 2).Value = strDName
xlSheet.Cells(intIndex, 3).Value = strSAM
xlSheet.Cells(intIndex, 4).Value = "None"
xlSheet.Cells(intIndex, 4).Font.Colorindex = 3
xlSheet.Cells(intIndex, 4).Font.Size = 8
xlSheet.Cells(intIndex, 4).HorizontalAlignment = xlRight
xlSheet.Cells(intIndex, 6).Value = "None"
xlSheet.Cells(intIndex, 6).Font.Colorindex = 3
xlSheet.Cells(intIndex, 6).Font.Size = 8
xlSheet.Cells(intIndex, 6).HorizontalAlignment = xlRight
xlSheet.Cells(intIndex, 7).Value = strDept
xlSheet.Cells(intIndex, 7).HorizontalAlignment = xlRight
xlSheet.Cells(intIndex, 7).Font.Size = 8
intIndex = intIndex + 1
xlSheet.Cells(intIndex, 1).Select
End Sub
Sub ProcessEachUser(strDName, strDept, strHomeDIR, strHomeDIRSize, strProfDIR, strProfDIRSize, _
strDisabled, strLocked)
If strDisabled = True Then
xlSheet.Cells(intIndex, 1).Value = "DISABLED"
Else If strLocked = True Then
xlSheet.Cells(intIndex, 1).Value = "LOCKED"
Else
xlSheet.Cells(intIndex, 1).Value = ""
End If
End If
With xlSheet.Cells(intIndex, 1)
.Font.Colorindex = 3
.Font.Size = 8
.HorizontalAlignment = xlRight
End With
xlSheet.Cells(intIndex, 2).Value = strDName
xlSheet.Cells(intIndex, 3).Value = strHomeDIR
xlSheet.Cells(intIndex, 4).Value = strHomeDIRSize
xlSheet.Cells(intIndex, 4).Font.Size = 8
xlSheet.Cells(intIndex, 5).Value = strProfDIR
xlSheet.Cells(intIndex, 6).Value = strProfDIRSize
xlSheet.Cells(intIndex, 6).Font.Size = 8
xlSheet.Cells(intIndex, 7).Value = strDept
xlSheet.Cells(intIndex, 7).HorizontalAlignment = xlRight
xlSheet.Cells(intIndex, 7).Font.Size = 8
If strHomeDIRSize >= 1000000000 Then
xlSheet.Cells(intIndex, 4).Font.Bold = True
intTotOverGB = intTotOverGB + 1
End If
If strHomeDIRSize >= 500000000 Then
xlSheet.Cells(intIndex, 4).Font.Bold = True
intTotOverMB = intTotOverMB + 1
End If
If strProfDIRSize >= 1000000000 Then
xlSheet.Cells(intIndex, 6).Font.Bold = True
intTotOverGB2 = intTotOverGB2 + 1
End If
If strProfDIRSize >= 500000000 Then
xlSheet.Cells(intIndex, 6).Font.Bold = True
intTotOverMB2 = intTotOverMB2 + 1
End If
If strHomeDIRSize = 0 Then
xlSheet.Cells(intIndex, 4).Value = "EMPTY"
xlSheet.Cells(intIndex, 4).Font.Colorindex = 3
xlSheet.Cells(intIndex, 4).HorizontalAlignment = xlRight
intTotEmpty = intTotEmpty + 1
Else
intFormatMB = FormatNumber(strHomeDIRSize/1024/1024,2,,,-1)
intTotSpaceUsed = intTotSpaceUsed + strHomeDIRSize
xlSheet.Cells(intIndex, 4).Value = intFormatMB & " MB"
xlSheet.Cells(intIndex, 4).HorizontalAlignment = xlRight
End If
If strProfDIRSize = 0 Then
xlSheet.Cells(intIndex, 6).Value = "EMPTY"
xlSheet.Cells(intIndex, 6).Font.Colorindex = 3
xlSheet.Cells(intIndex, 6).HorizontalAlignment = xlRight
intTotEmpty2 = intTotEmpty2 + 1
Else
intFormatMB2 = FormatNumber(strProfDIRSize/1024/1024,2,,,-1)
intTotSpaceUsed2 = intTotSpaceUsed2 + strProfDIRSize
xlSheet.Cells(intIndex, 6).Value = intFormatMB2 & " MB"
xlSheet.Cells(intIndex, 6).HorizontalAlignment = xlRight
End If
intIndex = intIndex + 1
xlSheet.Cells(intIndex, 1).Select
End Sub
Sub GetUsers(Path)
intTotUsersOU = 0
intGroup = intIndex - 1
Set objSubOU = GetObject("LDAP://" & Path)
objSubOU.Filter = Array("user")
For Each objUsr In objSubOU
If objUsr.sAMAccountName = "SOUTHERNCO$" Or objUsr.sAMAccountName = "SCFRD$" Or objUsr.sAMAccountName = "contract" Or _
objUsr.sAMAccountName = "TFTemplate" Or objUsr.sAMAccountName = "templateinfra" Or objUsr.HomeDIRectory = False Or _
objUsr.profilePath = False Then
Call ProcessEachUserShort(objUsr.displayName,objUsr.sAMAccountName,objUsr.AccountDisabled,objUsr.IsAccountLocked)
Else
Set objHomeDIR = FSO.GetFolder(objUsr.HomeDIRectory)
Set objProfDIR = FSO.GetFolder(objUsr.profilePath)
Call ProcessEachUser(objUsr.displayName,objUsr.department,objHomeDIR,objHomeDIR.size,objProfDIR,objProfDIR.size,objUsr.AccountDisabled,objUsr.IsAccountLocked)
End If
intTotUsers = intTotUsers + 1
intTotUsersOU = intTotUsersOU + 1
Next
'
' How to format cell if user data directory is Empty
' Where to place the user count
' Sort the users by column B, alphabetically and descending
'
If intTotUsersOU = 0 Then
xlSheet.Cells(intGroup, 2).Value = "EMPTY"
xlSheet.Cells(intGroup, 2).font.colorindex = 3
Else
xlSheet.Cells(intGroup, 2).Value = "Users = " & intTotUsersOU
xlSheet.Range("A" & intGroup + intTotUsersOU + 1 & ":G" & intGroup + 1).Sort xlSheet.Range("B" & intGroup + 1)
End If
End Sub
Sub GetOUs(Path)
Set objOU = GetObject("LDAP://" & Path)
'objOU.Filter = Array("organizationalUnit")
'For Each objSubOU In objOU
'strOUName = objSubOU.name
'strGrOUpDesc = objSubOU.ou
strOUName = objOU.name
strGrOUpDesc = objOU.ou
'
' Input OU header information into spreadsheet, start counting OU's
'
intTotOU = intTotOU + 1
intGroup = intIndex
xlSheet.Cells(intIndex, 1).Value = strOUName
xlSheet.Cells(intIndex, 7).Value = strGroupDesc
strGroupId = """" & strOUName & """"
'
' Start formatting the user data cells
'
With xlSheet.Range("A" & intIndex & ":G" & intIndex)
.Font.Bold = True
.Font.Size = 10
.Interior.ColorIndex = 14
.Interior.Pattern = 1 'xlSolid
.Font.ColorIndex = 2
.Borders.Weight = xlThick
End With
'
' intIndex equals the number of cells to count down before writing data
' Appended data starts being written on the next row in column A, i.e. A5, A6, etc.
'
intIndex = intIndex + 1
intTotUsersOU = 0
GetUsers objOU.distinguishedName
'GetUsers objSubOU.distinguishedName
'GetOUs objSubOU.distinguishedName
'Next
End Sub
Call GetOUs(strDomain1)
Call GetOUs(strDomain2)
Call GetOUs(strDomain3)
Call GetOUs(strDomain4)
'
' How to format the totals at the end of the spreadsheet
'
For ii = 1 To 2
xlSheet.Cells(intIndex + 2,ii).Font.Size = 12
xlSheet.Cells(intIndex + 2,ii).Font.Bold = True
Next
For ii = 1 To 2
xlSheet.Cells(intIndex + 3,ii).Font.Size = 12
xlSheet.Cells(intIndex + 3,ii).Font.Bold = True
Next
For ii = 1 To 2
xlSheet.Cells(intIndex + 5,ii).Font.Size = 12
xlSheet.Cells(intIndex + 5,ii).Font.Bold = True
Next
For ii = 1 To 2
xlSheet.Cells(intIndex + 6,ii).Font.Size = 12
xlSheet.Cells(intIndex + 6,ii).Font.Bold = True
Next
For ii = 1 To 2
xlSheet.Cells(intIndex + 7,ii).Font.Size = 12
xlSheet.Cells(intIndex + 7,ii).Font.Bold = True
Next
For ii = 1 To 2
xlSheet.Cells(intIndex + 8,ii).Font.Size = 12
xlSheet.Cells(intIndex + 8,ii).Font.Bold = True
Next
For ii = 1 To 2
xlSheet.Cells(intIndex + 9,ii).Font.Size = 12
xlSheet.Cells(intIndex + 9,ii).Font.Bold = True
Next
For ii = 1 To 2
xlSheet.Cells(intIndex + 11,ii).Font.Size = 12
xlSheet.Cells(intIndex + 11,ii).Font.Bold = True
Next
For ii = 1 To 2
xlSheet.Cells(intIndex + 12,ii).Font.Size = 12
xlSheet.Cells(intIndex + 12,ii).Font.Bold = True
Next
For ii = 1 To 2
xlSheet.Cells(intIndex + 13,ii).Font.Size = 12
xlSheet.Cells(intIndex + 13,ii).Font.Bold = True
Next
For ii = 1 To 2
xlSheet.Cells(intIndex + 14,ii).Font.Size = 12
xlSheet.Cells(intIndex + 14,ii).Font.Bold = True
Next
For ii = 1 To 2
xlSheet.Cells(intIndex + 15,ii).Font.Size = 12
xlSheet.Cells(intIndex + 15,ii).Font.Bold = True
Next
xlSheet.Cells(intIndex + 2,1).Value = "Total OU's - "
xlSheet.Cells(intIndex + 2,1).HorizontalAlignment = xlRight
xlSheet.Cells(intIndex + 2,2).Value = intTotOU
xlSheet.Cells(intIndex + 3,1).Value = "Total Users - "
xlSheet.Cells(intIndex + 3,1).HorizontalAlignment = xlRight
xlSheet.Cells(intIndex + 3,2).Value = intTotUsers
xlSheet.Cells(intIndex + 5,1).Value = "Home Dir's:"
xlSheet.Cells(intIndex + 5,1).HorizontalAlignment = xlRight
xlSheet.Cells(intIndex + 5,1).Font.Underline = xlUnderlineStyleSingle
xlSheet.Cells(intIndex + 6,1).Value = "Empty - "
xlSheet.Cells(intIndex + 6,1).HorizontalAlignment = xlRight
xlSheet.Cells(intIndex + 6,2).Value = intTotEmpty
xlSheet.Cells(intIndex + 7,1).Value = "Total - "
xlSheet.Cells(intIndex + 7,1).HorizontalAlignment = xlRight
xlSheet.Cells(intIndex + 7,2).Value = intTotSpaceUsed
intFormatGB = FormatNumber(intTotSpaceUsed/1024/1024/1024,2,,,-1)
xlSheet.Cells(intIndex + 7,2).Value = intFormatGB & " GB"
xlSheet.Cells(intIndex + 8,1).Value = "> 500MB"
xlSheet.Cells(intIndex + 8,1).HorizontalAlignment = xlRight
xlSheet.Cells(intIndex + 8,2).Value = intTotOverMB
xlSheet.Cells(intIndex + 9,1).Value = "> 1GB"
xlSheet.Cells(intIndex + 9,1).HorizontalAlignment = xlRight
xlSheet.Cells(intIndex + 9,2).Value = intTotOverGB
xlSheet.Cells(intIndex + 11,1).Value = "Profile Dir's:"
xlSheet.Cells(intIndex + 11,1).HorizontalAlignment = xlRight
xlSheet.Cells(intIndex + 11,1).Font.Underline = xlUnderlineStyleSingle
xlSheet.Cells(intIndex + 12,1).Value = "Empty - "
xlSheet.Cells(intIndex + 12,1).HorizontalAlignment = xlRight
xlSheet.Cells(intIndex + 12,2).Value = intTotEmpty2
xlSheet.Cells(intIndex + 13,1).Value = "Total - "
xlSheet.Cells(intIndex + 13,1).HorizontalAlignment = xlRight
xlSheet.Cells(intIndex + 13,2).Value = intTotSpaceUsed2
intFormatGB2 = FormatNumber(intTotSpaceUsed2/1024/1024/1024,2,,,-1)
xlSheet.Cells(intIndex + 13,2).Value = intFormatGB2 & " GB"
xlSheet.Cells(intIndex + 14,1).Value = "> 500MB"
xlSheet.Cells(intIndex + 14,1).HorizontalAlignment = xlRight
xlSheet.Cells(intIndex + 14,2).Value = intTotOverMB2
xlSheet.Cells(intIndex + 15,1).Value = "> 1GB"
xlSheet.Cells(intIndex + 15,1).HorizontalAlignment = xlRight
xlSheet.Cells(intIndex + 15,2).Value = intTotOverGB2
'
'Selects cell A1, saves the workbook, sets the variables to nothing and quits
'
xlSheet.Cells(1,1).Select
xlWrkBk.Save
Set WSHShell = Nothing
Set objXL = Nothing
Set xlWrkBk = Nothing
Set xlSheet = Nothing
Set FSO = Nothing
Set objHomeDIR = Nothing
Set objProfDIR = Nothing
Set objSubOU = Nothing
Set objOU = Nothing
WScript.Quit