1

I want a function to allow me to pass in either a device ID or a display name, and to do stuff with it. In the following example, I pass in a customer PS object that only contains a device ID ($obj.ID | Test-Function), but both $DisplayName and $Id end up with that value.

How do I force the value into the correct parameter?

Thanks.

function Test-Function {
[CmdletBinding()]
    Param (
        [Parameter(
            Mandatory=$true,
            ValueFromPipeline=$true,
            ValueFromPipelineByPropertyName=$true
        )]
        [string]$DisplayName

        [Parameter(
            Mandatory=$true,
            ValueFromPipeline=$true,
            ValueFromPipelineByPropertyName=$true
        )]
        [string]$Id
    )
    Begin {
        #Code goes here
    }
    Process {
        Write-Host "displayname is: $DisplayName" -ForegroundColor Green
        Write-Host "displayname is: $Id" -ForegroundColor Green        
    }
}
StackExchangeGuy
  • 741
  • 16
  • 36

0 Answers0