Get profile size of last logged on user

답변됨 Get profile size of last logged on user

  • Wednesday, November 14, 2012 12:27 AM
     
     

    Hi all,

    I am trying to query some machines on our network to find out an average user data size. My intent is to find the last logged on user and get the size of their full profile. I will then subtract that number from whatever a default unedited profile size is. This should give me a good idea of what amount of personal data they have. All the clients are running XP so it will have to use the C:\Documents and Settings\Username path

    Any idea how to accomplish this with power shell? Also does this sound like a reasonable way to accomplish this task?

All Replies

  • Wednesday, November 14, 2012 6:37 PM
     
      Has Code

    Here is what I have for a start. This gets me the filesize of a local directory. This is not much, but its a start for a script noobie like me

    cls 
    $Location = Read-Host "What directory do you want the size of?" 
    $size = (Get-ChildItem $Location -recurse | Measure-Object -property length -sum) 
    "{0:N2}" -f ($size.sum / 1024) + " KB" 

    I am now trying to incorporate it to grab a directory from a remote machine using UNC path or a list from a text file.

    Any input is appreciated, I will continue to update my code as I progress. 

  • Wednesday, November 14, 2012 6:43 PM
    Moderator
     
     Answered Has Code

    Hi,

    I wrote a script for the scripting guy blog a while back that calculates directory size statistics:

    http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/25/getting-directory-sizes-in-powershell.aspx

    This script can accept pipeline input, so you can create a text file of paths and pipe it to the script; e.g.


    PS C:\> get-content paths.txt | get-dirstats | export-csv output.csv -notypeinformation

    ...or something similar.

    Bill

    • Marked As Answer by echosummet Wednesday, November 14, 2012 7:32 PM
    •  
  • Wednesday, November 14, 2012 6:51 PM
     
     
    Thank you for the reply. I gave that script a shot but it doesnt seem to output the actual directory size, in mb or kb. Am I missing something?
  • Wednesday, November 14, 2012 6:53 PM
    Moderator
     
     

    I can't see your screen. What's the exact command you're running, and the exact output you're getting?

    Bill

  • Wednesday, November 14, 2012 6:57 PM
     
      Has Code

    Here was the command

    PS D:\Scripts\Powershell Scripts> Get-Content paths.txt | .\DirStats.ps1 | expor
    et-csv output.csv -notypeinformation


    This was the output.

    IsFixedSize	IsSynchronized	Keys	Values	SyncRoot	Count
    FALSE	FALSE	System.Collections.Hashtable+KeyCollection	System.Collections.Hashtable+ValueCollection	System.Object	2
    FALSE	FALSE	System.Collections.Hashtable+KeyCollection	System.Collections.Hashtable+ValueCollection	System.Object	2
    FALSE	FALSE	System.Collections.Hashtable+KeyCollection	System.Collections.Hashtable+ValueCollection	System.Object	2
    

    I have a UNC path in the paths.txt in the form \\compName\c$\users\UserName\Folder



  • Wednesday, November 14, 2012 7:03 PM
    Moderator
     
     

    What is the exact content of the file paths.txt? (post the first 3 or 4 lines)

    Bill

  • Wednesday, November 14, 2012 7:05 PM
     
     

    As of right now it only has this

    \\machineName\c$\users\UserName\desktop

    as a test. machineName and UserName have been changed to generics for this post

  • Wednesday, November 14, 2012 7:14 PM
    Moderator
     
      Has Code

    You're using this exact command?


    PS D:\Scripts\Powershell Scripts> get-content paths.txt | .\Get-DirStats.ps1 | export-csv output.csv -notypeinformation

    Of course, I am assuming that Get-DirStats.ps1 is the full script downloaded from the script repository (the link to it is in the blog article).

    What format is the file paths.txt? (Open it in Notepad, select File|Save As, and check the Encoding drop-down box.)

    Bill




  • Wednesday, November 14, 2012 7:18 PM
     
     

    Yep that exact command. The encoding is ANSI

    Thanks 

  • Wednesday, November 14, 2012 7:21 PM
    Moderator
     
     

    Are you sure you downloaded the Get-DirStats.ps1 script from the script repository and placed it in the directory 'D:\Scripts\Powershell Scripts'?

    Bill

  • Wednesday, November 14, 2012 7:26 PM
     
      Has Code

    Yep. I will redownload and try it again just to verify. 

    On another note I have altered my little script in the mean time and have come up with this

    cls 
    $Location = Read-Host "What directory do you want the size of?" 
    $size = ((Get-ChildItem $Location -Recurse) | Measure-Object -Sum Length).sum
    "{0:N2}" -f ($size / 1024) + " KB" 

    This works perfect if I input the path. What I need it to do next is pull a list of machines from a text file, find the most recently modified profile directory, then run the script to get folder size.

    Does this sound feasible?

  • Wednesday, November 14, 2012 7:31 PM
     
     

    I reran your script and it works beautifully. Perhaps something got truncated during the copy/paste.

    I appreciate your assistance! Although I am a little bummed I didnt write it out myself lol. Thanks again.


    Although it doesnt accomplish exactly what I need in that I would have to manually find the most recently edited profile, I can work with it.
    • Edited by echosummet Wednesday, November 14, 2012 7:34 PM Add text/Grammar correction
    •