![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | 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) |
| Guest | 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) |
| Guest | 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) |
| Guest | 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) |
| Guest | 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 | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Invoking Cmdlet Get-Location from cmdlet,cant get Currnt Directory | Vikram | PowerShell | 2 | 06-05-2008 04:41 AM |
| Whether a cmdlet derives from cmdlet or pscmdlet | Marco Shaw | PowerShell | 1 | 09-19-2007 09:18 PM |
| Invoking a cmdlet from another cmdlet | Marco Shaw | PowerShell | 2 | 09-19-2007 12:46 PM |
| Suggestion: I submitted a suggestion for a Generic Soap Cmdlet via Connect. Please check it out and vote. | Brandon Shell | PowerShell | 7 | 12-29-2006 08:11 AM |
| Invoke Cmdlet from a Cmdlet | =?Utf-8?B?ZnV6enkzMzM=?= | PowerShell | 3 | 08-25-2006 07:49 AM |