Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enumerating OU's in AD

Status
Not open for further replies.

isd503

MIS
Jul 16, 2004
4
US
I am having some trouble trying to select sub OU's within an AD structure:
_________________________________

Sub GetOUs(Path)
Set OUs = GetObject("LDAP://" & Path)
OUs.Filter = Array("organizationalUnit")
For Each OU In OUs
strOUName = OU.name
strGroupDesc = OU.ou

'
' Input OU header information into spreadsheet, start counting OU's
'
iTotOU = iTotOU + 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
iTotUsersOU = 0
GetUsers OU.distinguishedName
GetOUs OU.distinguishedName
Next
End Sub
_________________________________

How can I further filter the OU's. I tried the following statement after line 5 with no results:

If OU.ou = "Contractor" Then
 
I use ado when I need to enumerate the subtrees of ad
I did not test this but maybe this will help.

Sub GetOUs(Path)

'****************Setup ADSI connection and populate ADSI Collection************************************************

Set objADOconnADSI = CreateObject("ADODB.Connection")
objADOconnADSI.Open "Provider=ADsDSOObject;"
Set objCommandADSI = CreateObject("ADODB.Command")
objCommandADSI.ActiveConnection = objADOconnADSI

objCommandADSI.Properties("Size Limit")= 10000 ' ldap will only return the furst 1000 results by default this
objCommandADSI.Properties("Page Size")= 10000 ' will set it to 10000.

objCommandADSI.Properties("Sort on") = "ou" 'Omit this line if you don't need the record set to be sorted

' Include any field that you wish to
' be in the record set.
objCommandADSI.CommandText = "<LDAP://saws.org>;(objectClass=organizationalUnit);name,distinguishedname,ou;subtree"
Set objRSADSI = objCommandADSI.Execute

do while NOT objRSADSI.EOF
if lcase(objRSADSI.Fields("ou")) = "contractors" then
strOUName = objRSADSI.Fields("name")
strGroupDesc = objRSADSI.Fields("ou")

'
' Input OU header information into spreadsheet, start counting OU's
'
iTotOU = iTotOU + 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
iTotUsersOU = 0
GetUsers objRSADSI.Fields("distinguishedName")
GetOUs objRSADSI.Fields("distinguishedName")
end if
objRSADSI.MoveNext
loop
objRSSQL.Close
End Sub
 
Hello isd503,

Do you ever get passed OU.ou? What is it?! If you want the description, as your variable name suggested, it is OU.description.

You can devise a recursive function to do that and it will stop itself when no sub ou is found...
Code:
Set OUs = GetObject("LDAP://" & Path)
'do some preparation things on the OUs
do_and_enumsub_ou OUs
'do some other cleaning up thins
Set OUs = nothing

sub do_and_enumsub_ou (oOU)
    'do some intended work on the oOU here
    oOU.filter=array("organizationalUnit")
    for each osubOU in oOU
        do_and_enumsub_ou osubOU
    next
end sub
regards - tsuji
 
Tsuji -

Thank you for your response, but I am not sure what you mean. Let me try to be a little more specific about what I am trying to do.

This script looks into every OU in our AD structure and enumerates all users. It gathers information and puts it into an Excel spreadsheet.

My problem is I cannot figure our how to narrow the scope of the script to only those OU's I need to look in.

The script is initially filtered to look for users only in OU objects, and then I would like to further filter it using the OU.ou property. Many of our OU's do not have a description property.

 
Sorry I had some errors on the early posted script. Here I have tested this one and maybe it will help. I included an if test to list only those ou's with the word "contractor" in it. I used the lcase to get around the case sensitive issues but this means that you must make your compare string all lower case.


Set objADOconnADSI = CreateObject("ADODB.Connection")
objADOconnADSI.Open "Provider=ADsDSOObject;"
Set objCommandADSI = CreateObject("ADODB.Command")
objCommandADSI.ActiveConnection = objADOconnADSI

objCommandADSI.Properties("Size Limit")= 10000 ' ldap will only return the furst 1000 results by default this
objCommandADSI.Properties("Page Size")= 10000 ' will set it to 10000.

objCommandADSI.Properties("Sort on") = "ou" 'Omit this line if you don't need the record set to be sorted

' Include any field that you wish to
' be in the record set.
objCommandADSI.CommandText = "<LDAP://Your-domain.com>;(objectClass=organizationalUnit);name,distinguishedname,ou;subtree"
Set objRSADSI = objCommandADSI.Execute

do while NOT objRSADSI.EOF
if instr(lcase(objRSADSI.Fields("name")), "contractor") > 0 then
strOUName = objRSADSI.Fields("name")
wscript.echo strGroupDesc

'enter your code here and don't forget to change the LDAP://Your-domain.com line to macth your domain.



end if
objRSADSI.MoveNext
loop
objRSADSI.Close
 
isd503,

To get _only_ to "contractor", the block structure is something like this.
Code:
Set OUs = GetObject("LDAP://" & Path)
'do some preparation things on the OUs
do_and_enumsub_ou OUs
'do some other cleaning up thins
Set OUs = nothing

sub do_and_enumsub_ou (oOU)
    'do some intended general work on the any oOU here
    'you may well do nothing
    if strcomp(1,oOU.name,"contractors",1)<>0 then
        oOU.filter=array("organizationalUnit")
        for each osubOU in oOU
            do_and_enumsub_ou osubOU
        next
    else
        'do specific work on "contractors" ou here
        exit sub
    end if
end sub
Only shortcoming is that as such you have no dedicated signal that "contractors" ou does exist and is encountered. You can make a global boolean variable as indicator.

isd503, my postings are in reaction to your algorithm outlined. The directory ou-walk works but it is not as efficient as fosterr2000 care to post. A general search conducted on the db using ado is a direct approach for big ad. The ou-walk does illustrate the thing in a fundamental perspective, namely what nested ou means by nesting. So, look at what fosterr2000 suggestion more closely will be a good learning step to deal with it later.

- tsuji
 
how about a simple dsquery ou? This will list all the OUs in AD.

Marty
Network Admin
Hilliard Schools
 
martyh, what happens if you want to act on the list returned? or want to act on the OU based on some criteria?do you then have to write a script to read the output of 'dsquery ou' and then bind to the OU based on your criteria?
i would say this wouldnt be the most efficient approach.
perhaps if all you wanted was a list of the OU's then 'dsquery ou' would be ok.
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top