Community Page
- HuddledMasses.org/ Jump to website »
-
Subscribe -
Community
-
Top Commenters
-
Popular Threads
-
Recent Comments
- Thanks for the plugins Jaykul! I'm using them on my website which I just migrated from textpattern to wordpress and they are working great... There is just one little problem I am having... It...
- I was able to download the wmv-hd and the powerpoint ones. I gathered info from www.microsoftpdc.com but it seems some formats are not available yet.
- Were you able to get anything aside from wmv to work, Joel?
- Hey Jaykul, I've got some experience with this that I'm happy to share. I've used a Tivo (and hacked it to add a larger hard drive), a Comcast DVR, a Windows XP Media Center with an...
- Hey Joel, Ars Technica is also live tweeting the keynotes here: http://twitter.com/arspdc
Huddled Masses
Joel Bennett's development blog...
In a continuation of what is, sadly, becoming a series on how the PowerShell Pipeline works … Karl Prosser brought to my attention that certain powershell commands which have an -InputObject parameter don’t actually work when you pass something into it … so
... Continue reading »
1 year ago
You know, I've looked at your articles about cmdlets/functions in the pipeline and I feel you're missing something. The purpose of the InputObject parameter is to pass in a collection as a single object. This is as opposed to using the pipeline where a collection is passed along the pipeline one item at a time. There are cases where you want to pass in a collection as a collection.
In this particular article, you mention how certain cmdlets don't actually work when you use the InputObject parameter. But if you look at your example (Select -First 3 -Unique -InputObject $a), this does in fact work. It receives one object, an array. It then selects the first 3 objects, but there is only 1 so that is moot. And lastly it selects unique objects, but again there is only 1 so that is moot as well and finally the object is output using the default formatter. In this case the default formatter is showing the contents of the array. Look at these two examples:
Select -First 3 -Unique -InputObject $a | % { $_.ToString() }
$a | Select -First 3 -Unique | % { $_.ToString() }
In the first case, the output is System.Object[]. which is correct because that is the default string conversion of a collection of objects. In the second case you see the same output as if you didn't put the foreach-object cmdlet in the pipeline, which is also correct because the items in the collection are strings and therefore when you call ToString() on them you get them output as strings.
My point in all of this is that InputObject is actually a very useful parameter, because there are cases where you really want to pass a collection as a collection into a cmdlet and then do something with it. By making InputObject instead split the collection passed in and pipeline it through, you're forcing users to wrap collections in an array just to get them passed in as a collection, and personally I don't feel they should have to do that.
The only thing that I can see wrong with InputObject is that it isn't documented clearly enough.
I'd like to hear your thoughts on this, either here or via email because I've been working on cmdlets/functions that work in the pipeline lately and I have tried to follow the PowerShell core model of the InputObject parameter. I'd be interested in hearing arguments about how InputObject is broken so that I can make sure I'm making the right choice when it comes to that parameter.
--
Kirk Munro
Poshoholic
http://poshoholic.com
1 year ago
Quite simply, I disagree. The documentation for these parameters says quite clearly that inputObject “Specifies an object or objects to input to the cmdlet.†This clearly means that I should be able to pass multiple objects, *and have them treated as multiple objects*, not as a single array object. ... "More over here":http://huddledmasses.org/whats-the-desired-behavior-of-inputobject/
8 months ago
-inputobject $array[0]
SS
8 months ago