Results 1 to 4 of 4

Thread: scripts to list all users, home directories, and their home directories sizes

  1. #1
    Join Date
    Jul 2011
    Posts
    2

    scripts to list all users, home directories, and their home directories sizes

    I have a text file having specific users that I want to use to read in all my users to produce the list of users, home directories, and their home directories sizes. What are the codes I can put in the script to read in this specific users to produce an output file.

    Here is the script:


    ' Name : homedirectorysizev2.vbs
    ' Description : script to enumerate the home directories and their sizes of all users in Active Directory v2
    ' Author: David Ngwodo
    ' Version : 2.00
    ' Date : 07-15-2011


    arrAttributes = Array("homeDirectory","displayname","mail")

    Set adoCommand = CreateObject("ADODB.Command")
    Set adoConnection = CreateObject("ADODB.Connection")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    adoCommand.ActiveConnection = adoConnection

    Set objRootDSE = GetObject("LDAP://RootDSE")
    strBase = "<LDAP://" & objRootDSE.Get("defaultNamingContext") & ">"
    Set objRootDSE = Nothing

    strFilter = "(&(objectCategory=person)(objectClass=user)(homeDirectory=*))"
    strAttributes = Join(arrAttributes,",")
    Wscript.Echo Join(arrAttributes,";") & " ; home directory size in MB"
    strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
    adoCommand.CommandText = strQuery
    adoCommand.Properties("Page Size") = 100
    adoCommand.Properties("Timeout") = 30
    adoCommand.Properties("Cache Results") = False
    Set adoRecordset = adoCommand.Execute
    Do Until adoRecordset.EOF
    On Error Resume Next
    strTempOutput = ""
    For i = 0 To Ubound(arrAttributes)
    strTempOutput = strTempOutput & " ; " & adoRecordset.Fields(arrAttributes(i)).Value
    strOutput = Mid(Ltrim(strTempOutput),3)
    Next
    Wscript.Echo strOutput & " ; " & Foldersize (adoRecordset.Fields(arrAttributes(0)).Value) & " MB"
    adoRecordset.MoveNext
    Loop
    adoRecordset.Close
    adoConnection.Close
    Set adoRecordset = Nothing
    Set adoConnection = Nothing
    Set adoCommand = Nothing

    Function Foldersize(strPath)
    On Error Resume Next
    Set objNetwork = CreateObject("WScript.Network")
    Set objFSO = CreateObject("scripting.filesystemobject")
    objNetwork.MapNetworkDrive "h:", strPath
    Set objFld = objFSO.GetFolder("h:")
    Foldersize = Round(objFld.Size/1048576,2)
    objNetwork.RemoveNetworkDrive "h:"
    Set objFld = Nothing
    Set objFSO = Nothing
    End Function

  2. #2
    Join Date
    Jan 2006
    Posts
    605

    Re: scripts to list all users, home directories, and their home directories sizes

    Check the below simple script that produces a CSV with that information to list all home directories:

    Code:
    Dim rootDSE, domainObject
    Set rootDSE = GetObject("LDAP://RootDSE")
    domainContainer = rootDSE.Get("defaultNamingContext")
    Set domainObject = GetObject("LDAP://" & domainContainer)
    
    Set fs = CreateObject ("Scripting.FileSystemObject")
    Set outFile = fs.CreateTextFile (".\HomeDirs.txt")
    
    const crlf="<BR>"
    Set objExplorer = WScript.CreateObject("InternetExplorer.Application")
    objExplorer.Navigate "about:blank"   
    objExplorer.ToolBar = 0
    objExplorer.StatusBar = 0
    objExplorer.Width = 500
    objExplorer.Height = 300 
    objExplorer.Left = 100
    objExplorer.Top = 100
    
    Do While (objExplorer.Busy)
       Wscript.Sleep 200
    Loop
    
    objExplorer.Visible = 1    
    txtOutput=""
    
    
    If Right(strNewPath, 1) <> "\" then
       strNewPath = strNewPath & "\"
    End If
    strSearchContext = UCase(strSearchContext)
    
    outFile.WriteLine "User Name,Home Directory"
    exportUsers(domainObject)
    
    
    Set oDomain = Nothing
    showText("FINISHED!!")
    WScript.Quit
    
    
    
    Sub ExportUsers(oObject)
       Dim oUser
       For Each oUser in oObject
          Select Case oUser.Class
             Case "user"
    			outfile.WriteLine oUser.sAMaccountName & "," & oUser.homeDirectory
             Case "organizationalUnit" , "container"
                ExportUsers(oUser)
          End select
       Next
    End Sub
    
    
    Sub ShowText(txtInput)
       txtOutput = "Get Home Directory Path" & crlf
       txtOutput = txtOutput & "=======================" & crlf & crlf
       txtOutput = txtOutput & "Working on:  " & txtInput
       objExplorer.Document.Body.InnerHTML = txtOutput
    End Sub

  3. #3
    Join Date
    Jul 2011
    Posts
    2

    Re: scripts to list all users, home directories, and their home directories sizes

    What I need is a modification of codes that we use a text file with all the specific list of users e.g. c:\temp\users.txt to produce the list of users, home directories, home directories sizes.

  4. #4
    Join Date
    May 2008
    Posts
    4,085

    Re: scripts to list all users, home directories, and their home directories sizes

    It's not a script, just one command:

    Code:
    awk -F: '{print $1}' /etc/passwd
    If you want users with a specific shell:

    Code:
    grep "/sbin/nologin" /etc/passwd | awk -F: '{print $1}'

Similar Threads

  1. Website submission, art link directories list required?
    By skyjill86 in forum Operating Systems
    Replies: 2
    Last Post: 25-11-2009, 03:44 AM
  2. Batch file to list directories, export to CSV
    By chickenfriedsteak in forum Windows Server Help
    Replies: 1
    Last Post: 16-02-2009, 08:35 PM
  3. List all Files and Directories in a Directory
    By Samir_1 in forum Software Development
    Replies: 0
    Last Post: 08-12-2008, 07:32 PM
  4. Replies: 1
    Last Post: 12-05-2008, 05:15 AM
  5. Set home users home folder in VBS or GPO
    By Umedd in forum Active Directory
    Replies: 5
    Last Post: 18-02-2008, 12:10 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,694,926.57471 seconds with 17 queries