I have created a function with a parameter name ‘computername’. I want to accept value from pipeline, so I enabled ValueFromPipelineByPropertyName. Since I may be accepting pipeline info from get-adcomputer I set an alias to be 'Name".
When I run either of these commands it works as expected:
get-adcomputer -filter ‘name -like “dc”’ select name | my-function
get-adcomputer -Filter ‘name -like “trn_br1_w12”’ | select @{n=“ComputerName”;e={$_.name}} | My-Function
If I run this command it doesn’t produce any output
get-adcomputer -filter ‘name -like “dc”’ | my-function
If I change the parameter name to ‘Name’ and the alias to ‘ComputerName’ the command works as expected and gives me the results.
get-adcomputer -filter ‘name -like “dc”’ | my-function
Shouldn’t it work the same way for an alias as it does for the parameter?
function My-Function
{
[CmdletBinding()]
param
(
[Parameter(ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true)]
[Alias('Name')]
[string[]]$ComputerName,
[string]$LogName = '.\Deadfile.csv'
)