Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

A question about parameter binding

$
0
0

Hello All

Can someone please help me with the following question

I wrote a script that outputs a PSCustomObject (no problem there) which has a number of properties and values like so

 

ComputerName : Server01
LocalPort    : 21

I am certain the output is of type  System.Management.Automation.PSCustomObject  as I have check this.

I have another script and I want to Pipe the output of the first script to the second he parameter section of the second script looks like this

 

[cmdletbinding()]

param(

[parameter(Mandatory=$true,ValueFromPipeLine=$true,ValueFromPipeLineByPropertyName=$true)]

[alias("ComputerName")]

$URL,

[parameter(Mandatory=$true,ValueFromPipeLine=$true,ValueFromPipeLineByPropertyName=$true)]

[alias("LocalPort")]

$Port=443,

)

 

So basically the default name of the parameters are are URL and Port, but I have added an alias to each one called ComputerName and LocalPort  in order to try and match up with the incoming parameters e.g. ValueFromPipeLineByPropertyName   (I have tried adding and removing ValueFromPipeLine this does not fix my issue)

 

Rather than the in coming PSCustomObject  parameter ComputerName and LocalPort being bound to URL and Port (as I want) via their alias I get the following error

 

Get-CertOnPort : A positional parameter cannot be found that accepts argument '@{ComputerName=server01; LocalPort=21}'.

At line:1 char:91

+ ...  | select -First 1 | select ComputerName,LocalPort | Get-CertOnPort

+                                                          ~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (:) [Get-CertOnPort], ParameterBindingException

    + FullyQualifiedErrorId : PositionalParameterNotFound,Get-CertOnPort

It is basically stating 

PositionalParameterNotFound,Get

 

Any help please :)

 

Thanks

AAnotherUser__


Viewing all articles
Browse latest Browse all 6937

Trending Articles