List AD Users Home Drive and Size of Home Drive

This topic contains 4 replies, has 3 voices, and was last updated by  Don Jones 2 years, 3 months ago.

  • Author
  • #35944

    Jules Wale


    I am trying to gether together a report to show data grouth. I am trying to use powershell to list the AD Users.
    With this I would like to them work out the data grouth per user and per department.

    Get-ADUser -filter * -properties department, whencreated, homedrive, homedirectory | ft Name, department, whencreated, homedrive, homedirectory

    I would like to show the size of the users home drive.

    Get-size homedirectory -sum /1mb

    Please could someone help me put this together?



  • #35946

    Partho Sankar Roy

    I am not sure if you already have a function called Get-Size, If so you can redirect your previous output in a txt or csv file and then use for-each loop to gather the size of each users home drive.

    If you dont have that function ready using Get-ItemProperty would help you.

  • #35950

    Don Jones

    The only way to calculate the size of the home drive would be to add up the size of all the files in the home drive. You'd use Get-ChildItem (dir) to produce a list of files, and probably have it -recurse through subfolders, and then probably pipe that to Measure-Object, using the -sum option to generate the total size. It's going to be fairly time-consuming, and if this is on a file server could generate a certain amount of load. And you're not going to be able to do this in a straightforward one-liner. It'll be something like...

    Get-ADUser -filter * -properties department, whencreated, homedrive, homedirectory |
    ForEach-Object {
      $size = Dir $_.homedirectory -recurse | measure -sum
      $_ | Add-Member -MemberType NoteProperty -Name Size -Value $size.sum
    } | Ft Name, department, whencreated, homedrive, home directory, size

    That's probably not 100% going to work, but it's the basic gist. I'm adding a Size property to the user object, so that you can display that in your table.

    Unless your "Get-Size" function is a real thing that's already doing this.

  • #35968

    Jules Wale

    Hi when I run this I get this error:

    A positional parameter cannot be found that accepts argument 'System.Object[]'.
    At :line:5 char:6
    + } | FT <<<< Name, department, whencreated, homedrive, home directory, size

  • #35988

    Don Jones

    Oh, right – probably need to add -PassThru to the Add-Member command. Although as I was pointing out, that syntax IS PROBABLY NOT 100% CORRECT. It was intended to give you the gist of the logic you need, not to be a complete solution to your problem. I'm happy to answer questions about that logic, so you can troubleshoot the syntax effectively on your own.

You must be logged in to reply to this topic.