Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Are generic/polymorph CmdLet possible?

Reply
 
Old 11-08-2006   #1 (permalink)
Joannes Vermorel


 
 

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 SpecsSystem Spec
Old 11-08-2006   #2 (permalink)
Adam Milazzo


 
 

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 SpecsSystem Spec
Old 11-09-2006   #3 (permalink)
Joannes Vermorel


 
 

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 SpecsSystem Spec
Old 11-09-2006   #4 (permalink)
dreeschkind


 
 

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 SpecsSystem Spec
Old 11-09-2006   #5 (permalink)
Jacques Barathon [MS]


 
 

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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46