Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Are generic/polymorph CmdLet possible?

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 11-08-2006   #1 (permalink)
Joannes Vermorel
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 SpecsSystem Spec
Old 11-08-2006   #2 (permalink)
Adam Milazzo
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 SpecsSystem Spec
Old 11-09-2006   #3 (permalink)
Joannes Vermorel
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 SpecsSystem Spec
Old 11-09-2006   #4 (permalink)
dreeschkind
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 SpecsSystem Spec
Old 11-09-2006   #5 (permalink)
Jacques Barathon [MS]
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 SpecsSystem Spec
Closed Thread

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


Vistax64.com 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 2005-2008

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 47 48 49 50 51