Announcement

Collapse
No announcement yet.

Need to collect size of My Documents folder from multiple Workstations

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need to collect size of My Documents folder from multiple Workstations

    Hi,
    We are considering redirecting user My Documents folder to NAS and in an effort to perform some capacity planning, I need to determine the size of the My Documents folder on some 200 Workstations.
    Can anyone help me out with a script to do this, maybe point me to a resource where something similar to what I am looking for exists and I can tweak it to suit my needs?

    Thanks,
    Dov

  • #2
    Re: Need to collect size of My Documents folder from multiple Workstations

    this may assist:
    http://www.microsoft.com/technet/scr...pstip0404.mspx

    (scripting guy is helpful


    or this one:
    http://blogs.technet.com/heyscriptin...-computer.aspx
    Please do show your appreciation to those who assist you by leaving Rep Point https://www.petri.com/forums/core/im.../icon_beer.gif

    Comment


    • #3
      Re: Need to collect size of My Documents folder from multiple Workstations

      and this one:
      http://blogs.technet.com/heyscriptin...ts-folder.aspx

      Configure the vbscript to run as user logon script.

      The Size of the directory will be determined.
      The script also determines whether or not the My-Documents folder of the current user is local or on the network.
      Unique information will be written to a seperate file on a central share.

      Note,
      Two lines in the script below are rem'd out intentionally
      1) call updateTotal
      and
      2) WSHShell.Run """" & csvFile & """", 1, True
      The first one should be executed only when you decide to create a csv-file containing the Total size of all gathered My Documents folders unique information. You run the script manually and comment out the line again as soon you're done.
      The other line can only be executed when Excel is installed on your computer and you are executing 'call updateTotal'.

      Code:
      ' You must provide the unc path of a shared folder.
      ' users must have write and modify permisions on that folder.
      
      Const MY_DOCUMENTS = &H5&
      Const ForReading = 1
      Const ForWriting = 2
      
      Dim WshNetwork, strUsername, strComputername, Description
      Dim objFolder, Drv, FilePath, strFile, FolderSize1, FolderSize2
      Set WshNetwork = WScript.CreateObject("WScript.Network") 
      
      'Output to share (type unc name of the shared folder)
      FilePath = "\\networkServer\Sharename$"
      
      strUsername = WshNetwork.UserName
      strComputername = WshNetwork.ComputerName 
      
      Dim objFSO, strMY_DOCUMENTS, objFile ' Global scopes
      Set objFSO = CreateObject("Scripting.FileSystemObject")
      
      With CreateObject("Shell.Application").Namespace(MY_DOCUMENTS)
         strMY_DOCUMENTS = .Self.Path
         Set objFolder = objFSO.GetFolder(strMY_DOCUMENTS)
         drv = objFolder.drive
      End With
      
      ' Determine drivetype of the My Documents Folder
      Description = strUsername & "'s Documents on "
      If (DriveIsLocal(drv) = True) Then
         Description = Description & strComputername
      Else
         Description = Description & "Fileserver"
      End If
      strFile = FilePath & "\" & Description & ".txt"
      
      ' convert byte to megabyte (1 megabyte = 1 048 576 byte)
      FolderSize1 = objFolder.Size ' bytes
      FolderSize2 = RoundFormatNumber(FolderSize1/1048576, 2) ' megabytes
      
      Set objFile = objFSO.OpenTextFile(strFile, ForWriting, True)
      objFile.write     FolderSize1 & ",""" & Description
      objFile.writeline """,""[" & FolderSize2 & " MB]"""
      objFile.close: Set objFile = Nothing
      
      ' *** merge info ***
      rem call updateTotal  '(for logon scripts this line is rem'd-out)
      
      
      Function RoundFormatNumber(NumberToRound, aDecimalPlaces)
         ' The prefixed Round() function performs round to even.
         ' While this function performs round to larger.
           Dim nFactor
           nFactor = 10 ^ aDecimalPlaces
           RoundFormatNumber = FormatNumber(Int((NumberToRound * nFactor) _
             + 0.5) / nFactor, aDecimalPlaces)
      End Function
      
      Function DriveIsLocal(drive)
         DriveIsLocal = TRUE
         If Not Left(drive,2) = "\\" Then
           With GetObject("WinMgmts:{impersonationLevel=impersonate}" _
               & "!root/cimv2:Win32_LogicalDisk='"& drive & "'")
             If .DriveType = 4 Then DriveIsLocal = FALSE
           End With
         Else
           DriveIsLocal = FALSE
         End If
      End Function
      
      Sub updateTotal
         ' merge (this part not used in the logon script!)
         Dim csvFile, WSHShell, strCommand
         colFiles = FilePath & "\*'s Documents on *.txt"
         csvFile = FilePath & "\MY_DOCUMENTS total size.csv"
         Set WSHShell = WScript.CreateObject ("WScript.Shell")
         strCommand = "cmd /c Copy /b """ & colFiles & """"
         strCommand = strCommand & " """ & csvFile & """"
         WSHShell.Run strCommand, 0, True
         Set objFile = objFSO.OpenTextFile(csvFile, ForReading)
         tt1 = 0 : iCnt = 0
         Do While objFile.AtEndOfStream <> True
           iCnt = iCnt + 1
           tt1 = tt1 + split(objFile.Readline, ",")(0)
         Loop
         tt2 = RoundFormatNumber(tt1/1048576, 2)
         WSHShell.Run "cmd /c >>""" & csvFile & """ echo\,,", 0, True
         strCommand = "cmd /c >>""" & csvFile & """ echo\" & tt1 
         strCommand = strCommand & ",""Users = " & iCnt
         strCommand = strCommand & """,""[" & tt2 & " MB]"""
         WSHShell.Run strCommand, 0, True
         rem WSHShell.Run """" & csvFile & """", 1, True '(requires Excel)
      End Sub
      \Rems

      This posting is provided "AS IS" with no warranties, and confers no rights.

      __________________

      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts

      Comment

      Working...
      X