I have a function which creates an object which has a property name of 'Incident Number':
Function Get-ID {
New-Object -TypeName PSObject -Property @{'Incident Number' = 'INC12345'; 'Other Stuff' = 'Blah'}
}
I want to send that 'Incident Number' value in to another function via the pipeline, but in the second function the input property is named 'ID':
Function Get-Note {
Param(
[Parameter(ValueFromPipeline)]
[string]$ID
)
Write-Output "The input was $ID"
}
While it is possible to have a variable name with spaces (e.g ${Incident Number}) this then makes it awkward to use as a parameter at the command-line.
As defined above, the output is:
The input was @{Other Stuff=Blah; Incident Number=INC12345}
Using [Parameter(ValueFromPipelineByPropertyName)] returns:
Get-Note : 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.
FYI - The above is an example. In reality the properties of the object that is created by the first function are determined by an API call. While I could rename these properties as part of this function, my preference is to keep them as defined by the API.