![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Are generic/polymorph CmdLet possible? I would like to know if generic/polymorph are possible, i.e. is it possible to design a CmdLet that take whatever input found in the pipeline and pass it to the next CmdLet . Such generic CmdLet would be useful for monitoring or performing some agnostic .Net reflection driven (using attributes) operations on a generic PowerShell pipeline. Does anyone has an idea on this matter? Thanks in advance, Joannes http://www.peoplewords.com |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Are generic/polymorph CmdLet possible? Joannes Vermorel wrote: > I would like to know if generic/polymorph are possible, i.e. is it possible > to design a CmdLet that take whatever input found in the pipeline and pass it > to the next CmdLet . Can you describe what you're looking for more specifically? I mean, the foreach-object cmdlet can pass something to the next pipeline... previous | % { $_ } | next It's not clear what you're looking for. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Are generic/polymorph CmdLet possible? > Can you describe what you're looking for more specifically? > I mean, the foreach-object cmdlet can pass something to the next pipeline... What I was looking for what not very specific, merely understanding the extend of the PowerShell expressiveness. For example, let' consider Get-PipedBytes, a cmdlet that measures through binary serialization the amount of data (in bytes) that pass through the pipeline; but that has no effect otherwise (can be inserted anywhere with no effect). Is such a cmdlet possible? Joannes |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Are generic/polymorph CmdLet possible? "Joannes Vermorel" wrote: > For example, let' consider Get-PipedBytes, a cmdlet that measures through > binary serialization the amount of data (in bytes) that pass through the pipeline; > but that has no effect otherwise (can be inserted anywhere with no effect). > > Is such a cmdlet possible? I don't think so. The PowerShell pipeline works a little bit different than the pipe in other shells. AFAIK the "object flow engine" passes only references to the actual objects from one cmdlet to the next in the pipeline. This is possible because all Cmdlets run in the same process and not as different processes like in other shells. -- greetings dreeschkind |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Are generic/polymorph CmdLet possible? "Joannes Vermorel" <JoannesVermorel@discussions.microsoft.com> wrote in message news:6C0FCD0B-D714-443B-8C2E-39142A3E718D@microsoft.com... >> Can you describe what you're looking for more specifically? >> I mean, the foreach-object cmdlet can pass something to the next >> pipeline... > > What I was looking for what not very specific, merely understanding the > extend of the PowerShell expressiveness. For example, let' consider > Get-PipedBytes, a cmdlet that measures through binary serialization the > amount of data (in bytes) that pass through the pipeline; but that has no > effect otherwise (can be inserted anywhere with no effect). > > Is such a cmdlet possible? I never wrote a cmdlet but I am rather confident that PowerShell offers you with the possibility to access any property of an object and send it back to the pipeline for further processing. It is done by several built-in cmdlets which implement a -passthru parameter, or by tee-object which at the same time copies the objects to a file or variable and sends them to the next command in the pipeline. As for your example get-PipedBytes, here is a very basic filter which can "sort of" illustrate it: PS> $global:TotalSize=0 PS> $global:TotalCount=0 PS> filter filter-object { >> $global:TotalSize+=[system.runtime.interopservices.marshal]::sizeof($_) >> $global:TotalCount++ >> $_ >> } >> PS> 1..5|filter-object 1 2 3 4 5 PS> $TotalCount 5 PS> $TotalSize 20 The marshal.SizeOf() method doesn't work for all objects, but then you are battling with .Net limitations, not PowerShell's. Jacques |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Quest AD cmdlet -what is the cmdlet to remove computer object | PowerShell | |||
| Invoking Cmdlet Get-Location from cmdlet,cant get Currnt Directory | PowerShell | |||
| Whether a cmdlet derives from cmdlet or pscmdlet | PowerShell | |||
| Invoking a cmdlet from another cmdlet | PowerShell | |||
| Suggestion: I submitted a suggestion for a Generic Soap Cmdlet via Connect. Please check it out and vote. | PowerShell | |||