'Creating a powershell function that will take on ONE parameter and outputs a concatenated string value (fname+lname)
I'm looking for some guidance or tips for how to revise the function below. My goal is create a function that accepts one parameter and then returns a string. In this case the string will be a name of a super hero. The catch is that the function must output the full name concatenated together (ex. $FullName = $FName + "" +$LName). Can anyone give me some guidance on how I can accomplish this?
So far a have functional function that accepts one parameter but the output is the full name as one singular string. I am unable to find away to concatenate a first and last name and use it as my single parameter for this function. The commented out section of the function is just some trial and error code that I have attempted so far. Any help is appreciated!
The strings I'm working with:
Bat Man, Wonder Woman, Aqua Man
function Get-DCHero {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)][ValidateSet('Batman','Superman','Aquaman','Wonder Woman',ErrorMessage = "'{0}' is not a DC Super Hero. Please trying one of the following: '{1}'")]
[string]$Name
<#
[Parameter(Mandatory=$true)][ValidateSet('Batman','Superman','Aquaman','Wonder Woman',ErrorMessage = "'{0}' is not a DC Super Hero. Please trying one of the following: '{1}'")]
[string]$FullName = $FName + "" +$LName
[ValidateSet('Bat','Super','Aqua','Wonder','Flash',ErrorMessage = "'{0}' is not a DC Super Hero. Please trying one of the following: '{1}'")]
[string]$FName
[ValidateSet('Man','Man','Man','Woman','Flash',ErrorMessage = "'{0}' is not a DC Super Hero. Please trying one of the following: '{1}'")]
[string]$LName
#>
)
Write-OutPut "$Name is a DC Super hero."
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|