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

cmdlet dev help

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 07-19-2007   #1 (permalink)
Darren Mar-Elia
Guest


 

cmdlet dev help

I have one cmdlet that I wrote whose output is an object of a particular
type. I'm writing another cmdlet that takes as one of its parameters, that
object type of the first cmdlet. However in my testing I can't seem to find
the correct syntax to pipe the output of the first cmdlet to the parameter
of the 2nd. What is the general format for something like this. I feel like
I'm missing something basic here.

I tried:

get-mycmdlet | get-my2ndcmdlet $_ -param foo -param2 foo2

?
Darren


My System SpecsSystem Spec
Old 07-19-2007   #2 (permalink)
Marco Shaw
Guest


 

Re: cmdlet dev help

Darren Mar-Elia wrote:
> I have one cmdlet that I wrote whose output is an object of a particular
> type. I'm writing another cmdlet that takes as one of its parameters,
> that object type of the first cmdlet. However in my testing I can't seem
> to find the correct syntax to pipe the output of the first cmdlet to the
> parameter of the 2nd. What is the general format for something like
> this. I feel like I'm missing something basic here.
>
> I tried:
>
> get-mycmdlet | get-my2ndcmdlet $_ -param foo -param2 foo2
>
> ?
> Darren
>


Could you show us how you've defined your parameters. You'd have to
define your parameter attributes like so:

[Parameter(
Position = 0,
ValueFromPipeline = true,
ValueFromPipelineByPropertyName = true
)]

The SDK has a section on this exact thing ("Adding Parameters that
Process Pipeline Input"), and it explains the 2nd and 3rd value above.

Marco
My System SpecsSystem Spec
Old 07-19-2007   #3 (permalink)
Darren Mar-Elia
Guest


 

Re: cmdlet dev help

Thanks Marco-
I am using those attributes in my parameter definition. I have a feeling my
problem is that the output of my first cmdlet is a COM object. If I run it
as below, I get:

get-my2ndcmdlet : The argument cannot be null or empty.

If I assign the output of the first cmdlet to a variable first and then feed
the variable to the 2nd cmdlet, I get:

get-my2ndcmdlet : A parameter cannot be found that matches parameter name
'System.__ComObject'.

Darren



"Marco Shaw" <marco.shaw@_NO_SPAM_gmail.com> wrote in message
news:O$%23%23r%23lyHHA.5964@TK2MSFTNGP04.phx.gbl...
> Darren Mar-Elia wrote:
>> I have one cmdlet that I wrote whose output is an object of a particular
>> type. I'm writing another cmdlet that takes as one of its parameters,
>> that object type of the first cmdlet. However in my testing I can't seem
>> to find the correct syntax to pipe the output of the first cmdlet to the
>> parameter of the 2nd. What is the general format for something like this.
>> I feel like I'm missing something basic here.
>>
>> I tried:
>>
>> get-mycmdlet | get-my2ndcmdlet $_ -param foo -param2 foo2
>>
>> ?
>> Darren
>>

>
> Could you show us how you've defined your parameters. You'd have to
> define your parameter attributes like so:
>
> [Parameter(
> Position = 0,
> ValueFromPipeline = true,
> ValueFromPipelineByPropertyName = true
> )]
>
> The SDK has a section on this exact thing ("Adding Parameters that Process
> Pipeline Input"), and it explains the 2nd and 3rd value above.
>
> Marco


My System SpecsSystem Spec
Old 07-20-2007   #4 (permalink)
Darren Mar-Elia
Guest


 

Re: cmdlet dev help

I think I'm missing something basic about how cmdlets pass objects into the
pipeline. Hopefully someone can illuminate this for me. I have a cmdlet that
does a WriteObject of a custom type in my cmdlet. That type is actually a
COM Interop type that I use within my cmdlet. I want to be able to pass that
object, with its type intact, to another cmdlet that understands that
particular type. However it appears that when my object hits the pipeline,
its type is not preserved. When I try to consume it from the pipeline on my
2nd cmdlet, I get this error:

The input object cannot be bound to any parameters for the command either
because the command does not take pipeline input or the input and its
properties do not match any of the parameters that take pipeline input.

I am using the valuefrompipeline = true attribute on my parameter "Name" so
my understanding is that should grab the whole object. However, I have a
feeling that the object's type is being changed by PowerShell. Any way
around this?

Thanks

Darren



"Darren Mar-Elia" <dmanonymous@microsoft.com> wrote in message
news:74EC8E71-6C92-4247-B99E-E2CD99018B2E@microsoft.com...
> Thanks Marco-
> I am using those attributes in my parameter definition. I have a feeling
> my problem is that the output of my first cmdlet is a COM object. If I run
> it as below, I get:
>
> get-my2ndcmdlet : The argument cannot be null or empty.
>
> If I assign the output of the first cmdlet to a variable first and then
> feed the variable to the 2nd cmdlet, I get:
>
> get-my2ndcmdlet : A parameter cannot be found that matches parameter name
> 'System.__ComObject'.
>
> Darren
>
>
>
> "Marco Shaw" <marco.shaw@_NO_SPAM_gmail.com> wrote in message
> news:O$%23%23r%23lyHHA.5964@TK2MSFTNGP04.phx.gbl...
>> Darren Mar-Elia wrote:
>>> I have one cmdlet that I wrote whose output is an object of a particular
>>> type. I'm writing another cmdlet that takes as one of its parameters,
>>> that object type of the first cmdlet. However in my testing I can't seem
>>> to find the correct syntax to pipe the output of the first cmdlet to the
>>> parameter of the 2nd. What is the general format for something like
>>> this. I feel like I'm missing something basic here.
>>>
>>> I tried:
>>>
>>> get-mycmdlet | get-my2ndcmdlet $_ -param foo -param2 foo2
>>>
>>> ?
>>> Darren
>>>

>>
>> Could you show us how you've defined your parameters. You'd have to
>> define your parameter attributes like so:
>>
>> [Parameter(
>> Position = 0,
>> ValueFromPipeline = true,
>> ValueFromPipelineByPropertyName = true
>> )]
>>
>> The SDK has a section on this exact thing ("Adding Parameters that
>> Process Pipeline Input"), and it explains the 2nd and 3rd value above.
>>
>> Marco

>


My System SpecsSystem Spec
Old 07-21-2007   #5 (permalink)
klumsy@xtra.co.nz
Guest


 

Re: cmdlet dev help

does the com type happen to be a collection? if so powershell strips
collections and pipes each element of hte collection down the pipeline
at a time.

One thing you could do is just taketype your inputobject as Object,
that way at least you'll recieve the object, and then you could put
some code in your second cmdlet, to inspect, debug whats actually
coming through.

On Jul 20, 4:19 pm, "Darren Mar-Elia" <dmanonym...@microsoft.com>
wrote:
> I think I'm missing something basic about how cmdlets pass objects into the
> pipeline. Hopefully someone can illuminate this for me. I have a cmdlet that
> does a WriteObject of a custom type in my cmdlet. That type is actually a
> COM Interop type that I use within my cmdlet. I want to be able to pass that
> object, with its type intact, to another cmdlet that understands that
> particular type. However it appears that when my object hits the pipeline,
> its type is not preserved. When I try to consume it from the pipeline on my
> 2nd cmdlet, I get this error:
>
> The input object cannot be bound to any parameters for the command either
> because the command does not take pipeline input or the input and its
> properties do not match any of the parameters that take pipeline input.
>
> I am using the valuefrompipeline = true attribute on my parameter "Name" so
> my understanding is that should grab the whole object. However, I have a
> feeling that the object's type is being changed by PowerShell. Any way
> around this?
>
> Thanks
>
> Darren
>
> "Darren Mar-Elia" <dmanonym...@microsoft.com> wrote in message
>
> news:74EC8E71-6C92-4247-B99E-E2CD99018B2E@microsoft.com...
>
>
>
> > Thanks Marco-
> > I am using those attributes in my parameter definition. I have a feeling
> > my problem is that the output of my first cmdlet is a COM object. If I run
> > it as below, I get:

>
> > get-my2ndcmdlet : The argument cannot be null or empty.

>
> > If I assign the output of the first cmdlet to a variable first and then
> > feed the variable to the 2nd cmdlet, I get:

>
> > get-my2ndcmdlet : A parameter cannot be found that matches parameter name
> > 'System.__ComObject'.

>
> > Darren

>
> > "Marco Shaw" <marco.shaw@_NO_SPAM_gmail.com> wrote in message
> >news:O$%23%23r%23lyHHA.5964@TK2MSFTNGP04.phx.gbl...
> >> Darren Mar-Elia wrote:
> >>> I have one cmdlet that I wrote whose output is an object of a particular
> >>> type. I'm writing another cmdlet that takes as one of its parameters,
> >>> that object type of the first cmdlet. However in my testing I can't seem
> >>> to find the correct syntax to pipe the output of the first cmdlet to the
> >>> parameter of the 2nd. What is the general format for something like
> >>> this. I feel like I'm missing something basic here.

>
> >>> I tried:

>
> >>> get-mycmdlet | get-my2ndcmdlet $_ -param foo -param2 foo2

>
> >>> ?
> >>> Darren

>
> >> Could you show us how you've defined your parameters. You'd have to
> >> define your parameter attributes like so:

>
> >> [Parameter(
> >> Position = 0,
> >> ValueFromPipeline = true,
> >> ValueFromPipelineByPropertyName = true
> >> )]

>
> >> The SDK has a section on this exact thing ("Adding Parameters that
> >> Process Pipeline Input"), and it explains the 2nd and 3rd value above.

>
> >> Marco- Hide quoted text -

>
> - Show quoted text -



My System SpecsSystem Spec
Old 07-21-2007   #6 (permalink)
Marco Shaw
Guest


 

Re: cmdlet dev help

klumsy@xtra.co.nz wrote:
> does the com type happen to be a collection? if so powershell strips
> collections and pipes each element of hte collection down the pipeline
> at a time.
>
> One thing you could do is just taketype your inputobject as Object,
> that way at least you'll recieve the object, and then you could put
> some code in your second cmdlet, to inspect, debug whats actually
> coming through.


Where can I find more information on "taketype"? A simple google search
seems to give me hits of some kind of app with that name.

Marco
My System SpecsSystem Spec
Old 07-24-2007   #7 (permalink)
Darren Mar-Elia
Guest


 

Re: cmdlet dev help

Thanks. Its not a collection. I'm not familiar with "taketype". I do notice
that my object type that's output by my first cmdlet and put into the
pipeline is shown as
System.__ComObject#{58cc4352-1ca3-48e5-9864-1da4d6e0d60f}. Not sure what to
do with that .

--
Darren Mar-Elia
MS-MVP-Windows Server--Group Policy

Simplify Group Policy Troubleshooting with the NEW GPExpert Troubleshooting
Pak 1.0 at http://www.sdmsoftware.com/products.php

Visit the GPOGUY: http://www.gpoguy.com -- The Windows Group Policy
Information Hub:
FAQs, Training Videos, Whitepapers and Utilities for all things Group
Policy-related

<klumsy@xtra.co.nz> wrote in message
news:1185041407.665604.58950@e16g2000pri.googlegroups.com...
> does the com type happen to be a collection? if so powershell strips
> collections and pipes each element of hte collection down the pipeline
> at a time.
>
> One thing you could do is just taketype your inputobject as Object,
> that way at least you'll recieve the object, and then you could put
> some code in your second cmdlet, to inspect, debug whats actually
> coming through.
>
> On Jul 20, 4:19 pm, "Darren Mar-Elia" <dmanonym...@microsoft.com>
> wrote:
>> I think I'm missing something basic about how cmdlets pass objects into
>> the
>> pipeline. Hopefully someone can illuminate this for me. I have a cmdlet
>> that
>> does a WriteObject of a custom type in my cmdlet. That type is actually a
>> COM Interop type that I use within my cmdlet. I want to be able to pass
>> that
>> object, with its type intact, to another cmdlet that understands that
>> particular type. However it appears that when my object hits the
>> pipeline,
>> its type is not preserved. When I try to consume it from the pipeline on
>> my
>> 2nd cmdlet, I get this error:
>>
>> The input object cannot be bound to any parameters for the command either
>> because the command does not take pipeline input or the input and its
>> properties do not match any of the parameters that take pipeline input.
>>
>> I am using the valuefrompipeline = true attribute on my parameter "Name"
>> so
>> my understanding is that should grab the whole object. However, I have a
>> feeling that the object's type is being changed by PowerShell. Any way
>> around this?
>>
>> Thanks
>>
>> Darren
>>
>> "Darren Mar-Elia" <dmanonym...@microsoft.com> wrote in message
>>
>> news:74EC8E71-6C92-4247-B99E-E2CD99018B2E@microsoft.com...
>>
>>
>>
>> > Thanks Marco-
>> > I am using those attributes in my parameter definition. I have a
>> > feeling
>> > my problem is that the output of my first cmdlet is a COM object. If I
>> > run
>> > it as below, I get:

>>
>> > get-my2ndcmdlet : The argument cannot be null or empty.

>>
>> > If I assign the output of the first cmdlet to a variable first and then
>> > feed the variable to the 2nd cmdlet, I get:

>>
>> > get-my2ndcmdlet : A parameter cannot be found that matches parameter
>> > name
>> > 'System.__ComObject'.

>>
>> > Darren

>>
>> > "Marco Shaw" <marco.shaw@_NO_SPAM_gmail.com> wrote in message
>> >news:O$%23%23r%23lyHHA.5964@TK2MSFTNGP04.phx.gbl...
>> >> Darren Mar-Elia wrote:
>> >>> I have one cmdlet that I wrote whose output is an object of a
>> >>> particular
>> >>> type. I'm writing another cmdlet that takes as one of its parameters,
>> >>> that object type of the first cmdlet. However in my testing I can't
>> >>> seem
>> >>> to find the correct syntax to pipe the output of the first cmdlet to
>> >>> the
>> >>> parameter of the 2nd. What is the general format for something like
>> >>> this. I feel like I'm missing something basic here.

>>
>> >>> I tried:

>>
>> >>> get-mycmdlet | get-my2ndcmdlet $_ -param foo -param2 foo2

>>
>> >>> ?
>> >>> Darren

>>
>> >> Could you show us how you've defined your parameters. You'd have to
>> >> define your parameter attributes like so:

>>
>> >> [Parameter(
>> >> Position = 0,
>> >> ValueFromPipeline = true,
>> >> ValueFromPipelineByPropertyName = true
>> >> )]

>>
>> >> The SDK has a section on this exact thing ("Adding Parameters that
>> >> Process Pipeline Input"), and it explains the 2nd and 3rd value above.

>>
>> >> Marco- Hide quoted text -

>>
>> - Show quoted text -

>
>


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
Re: How to run following CmdLet using .NET John Vottero PowerShell 1 01-06-2008 09:23 PM
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
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