Get Home Directory Size for User

Welcome Forums General PowerShell Q&A Get Home Directory Size for User

  • This topic has 6 replies, 3 voices, and was last updated 2 months ago by
    J
    Participant
    .
Viewing 6 reply threads
  • Author
    Posts
    • #199199
      J
      Participant
      Topics: 3
      Replies: 6
      Points: 42
      Rank: Member

      I’m very new to powershell and wondered if somebody might be able to help with an issue please.

      I’m trying to return the size of a home drive for a specific user. The code I have come up with is:

      get-aduser -identity 'userADname' -properties homedirectory | get-childitem homedirectory -recurse | measure-object -property length -sum

      I’m obviously replacing ‘userADname’ with a relevant AD username.

      The error I’m getting is:

      get-childitem : The input object cannot be bound to any parameters for the command either because the
      command does not take pipeline input or the input and its properties do not match any of the parameters that
      take pipeline input.

      Thank you for any help.

    • #199232
      Participant
      Topics: 4
      Replies: 70
      Points: 192
      Helping Hand
      Rank: Participant

      Looking at the documentation for Get-ChildItem (Get-Help Get-ChildItem), there are 2 parameters that can take arguments over the pipeline: Path and LiteralPath.  Both will take arguments by PropertyName and Path will also take arguments by Value.  This means that:

      get-aduser -identity 'userADname' -properties homedirectory

      Must produce a string object to use for the Path parameter, or some other type of object that has a property named “LiteralPath” or “Path” with a string value that can be used as an argument in the Get-ChildItem command.  I would recommend taking your first section of code (copied above) and pipe it to Get-Member.  This will tell you what type of object is being returned along with it’s properties/methods.  This should explain why “The input object cannot be bound to any parameters for the command”

      Once you have determined the object type, the next step would be to make any changes necessary to the input object so it can be used by Get-ChildItem.  Recommend looking a PowerShell in a Month of Lunches chapter 9 specifically 9.5 “When things don’t line up: custom properties” for an explanation.

    • #199265
      J
      Participant
      Topics: 3
      Replies: 6
      Points: 42
      Rank: Member

      Thanks for your feedback Mike.

      I piped to get-member and saw that there was numerous types of information being returned, so I’m thinking that I need to tell it to specifically look at the HomeDirectory info?

      I’ve tried the following:

      get-aduser -identity 'userADname' -properties homedirectory | select-object -property homedirectory | get-childitem -recurse | measure-object -property length -sum

      This is throwing up a new error about not being able to find the path. I might be completely on the wrong track as this is all still very new.

      Thanks again.

       

       

    • #199268
      Jon
      Participant
      Topics: 13
      Replies: 226
      Points: 174
      Helping Hand
      Rank: Participant

      Step it through 1 by 1

       

      get-aduser testuser -properties homedirectory | select homedirectory

      Returns

      homedirectory
      ————-
      \\server\testuser

      This isn’t data that get-childitem can handle, get-childitem is looking for a unc path i.e \\server\testuser NOT that outputted object you see above. You can get what you need two different ways

      get-aduser testuser -properties homedirectory | select -expandproperty homedirectory 
      (get-aduser testuser -Properties homedirectory).homedirectory

      Which both output as:

      \\server\testuser

      Which you can successfully pipe to get-childitem

       

    • #199292
      J
      Participant
      Topics: 3
      Replies: 6
      Points: 42
      Rank: Member

      Thanks Jon, that’s great. Looking at the outputs after removing the pipes and adding them 1 by 1 helped to make sense of it and it’s working now.

      Is there an easy way of getting it to show the size in GB rather than bytes or is that adding a lot more complexity?

    • #199295
      Jon
      Participant
      Topics: 13
      Replies: 226
      Points: 174
      Helping Hand
      Rank: Participant
    • #199670
      J
      Participant
      Topics: 3
      Replies: 6
      Points: 42
      Rank: Member

      Thanks Jon, that’s really helpful.

Viewing 6 reply threads
  • You must be logged in to reply to this topic.