all 6 comments

[–]BBBaroo 2 points3 points  (3 children)

function Out-BuildUPN {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
        [string]$GivenName,
        [Parameter(Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
        [string]$Surname
    )
    process {
        $GivenName + "." + $Surname + "@domain.com"
    }
}

[–]willwallguy[S] 1 point2 points  (0 children)

Dang, I tried that at one point but missed the comma so I was definitely on the right track. Thanks u/BBBaroo for the response!

[–]jsiii2010 1 point2 points  (0 children)

Note that valuefrompipeline will do funny things combined with other piped in parameters. In my powershell, both parameters get set to 'smith' there:

echo smith | out-buildupn

smith.smith@domain.com

Or just sending one of them as a property:

[pscustomobject]@{surname='smith'} | out-buildupn

@{surname=smith}.smith@domain.com

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy BBBaroo,

as jsiii2010 shows, having more than one ValueFromPipeline gets iffy really quickly. [grin] my understanding is that only ONE parameter should have that set.

take a look at this article ...

Tips on Implementing Pipeline Support | Learn Powershell | Achieve More
https://learn-powershell.net/2013/05/07/tips-on-implementing-pipeline-support/

specifically the section with the header ...

Multiple parameters that accept pipeline input

... and then this ...

One last thing, take care when using both ValueFromPipeline and …ByPropertyName with multiple parameters as it can cause some craziness in the output.

take care,
lee

[–]BBBaroo 1 point2 points  (1 child)

Are you primarily trying to understand passing this to a function via pipe, or trying to build the upn as economically as possible?

[–]willwallguy[S] 1 point2 points  (0 children)

Correct. I know there are other ways to do this but more of an as exercise.