Re: [msh] Parameter input from argument or pipeline?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



The parameter binder cannot disambiguate the two conditions without
specifying the destination as a named parameter. Basically what it is doing
is first binding all the named parameters, then binding all the positional
arguments to the parameters that have not yet been bound, and then taking
pipeline input. (Note, there is really a lot more going on but I am
simplifying for this discussion.) Since you want to support Source as a
positional parameter with higher priority than Destination you have to give
it a lower number. This means that whenever you have a positional argument
specified on the command line and Source hasn't been explicitly set then the
positional argument will be bound to it before it will be bound to
Destination. The pipeline input isn't processed until all named and
positional arguments have been processed.

ValueFromPipelineByPropertyName tells the parameter binder to shred the
incoming object and look for a property of that object that matches the name
(or alias) of the parameter. For instance, copy-item has
ValueFromPipelineByPropertyName on the Path (alias of MshPath) parameter.
This allows objects coming from get-childitem item which have a property of
MshPath to be piped into the Path (alias of MshPath) parameter. However,
the parameter will not take a string directly as the Path parameter via
pipeline input unless ValueFromPipeline is also specified.

--
Jeff Jones [MSFT]
Monad Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.



"Nick" <Nick@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:9540B0C0-A902-4C19-8CA2-22559C77F815@xxxxxxxxxxxxxxxx
OK, I figured out the problem (for the most part):

when I tried to do

ls * | copy-custom C:\

it failed, but if I explicitly specify:

ls * | copy-custom -Destination C:\

it works. So now worries; it would be nice if I didn't have to specify the
parameter name, though.

Nick

"Nick" wrote:

I'm trying to design a cmdlet that, for one of the parameters, takes data
from the pipeline if it's there, and if not takes it from the first
argument
(it's a specialized copy command). So, I want all of these to do the same
thing:

ls ~/* | copy-custom C:\
copy-custom ~/* C:\
copy-custom -Source ~/* -Destination C:\

where copy-custom has one property Source that takes data from the
pipeline
(first command), argument by position (second), or argument by name
(third).

How do I do this? I notice that the copy-item cmdlet
(CopyItemCoreCommand)
doesn't allow this; is it not possible?

One a somewhat related note, how do you use the
ValueFromPipelineByPropertyName property on the Parameter attribute? I
initially expected it to solve exactly this problem, but it doesn't seem
to.
It is set on CopyItemCoreCommand.Path, but copy-item doesn't accept
pipeline
input, as far as I can tell.

Thanks,
Nick Howell


.



Relevant Pages

  • Re: Copy console to printer?
    ... BEN RITCHEY wrote: ... >>> archives under DOS (gives you the chance to actually specify ... >>> destination folder). ...
    (comp.os.msdos.misc)
  • Re: DTS handling bad dates
    ... Go to Properties of the Transform Data task, ... Specify an exception file e.g. MyImport.txt, ... format, but turn on Source rows and Destination rows, and increase the ... Note that because your increased Maximum Error Count to a high number, ...
    (microsoft.public.sqlserver.dts)
  • Re: How to create a .prn file?
    ... Tick the box "Print to File" ... Specify a destination when prompted. ...
    (microsoft.public.win2000.general)
  • Re: How to create a .prn file?
    ... a printer from the command line. ... Tick the box "Print to File" ... Specify a destination when prompted. ...
    (microsoft.public.win2000.general)