January 22, 2020 at 11:28 am #199199
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.
January 22, 2020 at 1:12 pm #199232ParticipantTopics: 4Replies: 70Points: 192Rank: 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.
January 22, 2020 at 3:50 pm #199265
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.
January 22, 2020 at 4:16 pm #199268ParticipantTopics: 13Replies: 226Points: 174Rank: Participant
Step it through 1 by 1
get-aduser testuser -properties homedirectory | select homedirectory
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:
Which you can successfully pipe to get-childitem
January 22, 2020 at 5:00 pm #199292
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?
January 22, 2020 at 5:05 pm #199295ParticipantTopics: 13Replies: 226Points: 174Rank: Participant
January 24, 2020 at 1:10 pm #199670
Thanks Jon, that’s really helpful.
- You must be logged in to reply to this topic.