I am wondering if there is an existing parameter attribute I can add to my function which will take the passed in value and make it lowercase. Here is an example function.
Now I understand that this can be easily done by updating the variable within the script of the function, but if there is a predefined parameter attribute that I can add to the param then I would like to use it instead.
P.S. - I have looked at MFST documentation and also tried a few methods myself to try and figure this out, but unfortunately I did not have any success.
Hi, Shane. Yes I agree with you completely and I am aware of this available method. However, I was looking for an Parameter attribute that may be available to me to do this. What you suggested is what I do today.
Hi Sam, I have a function that accepts a parameter which ultimately is used as information to invoke an API. However, the value that gets passed must be in lower case otherwise the API call doesn’t return anything. I was just wondering if there was an Parameter Attribute that I could use to control the param value in case someone else changes this down the road.
Yes I have. I thought about using both. However, I prefer to have people type in upper or lowercase node name and not have to worry about how they might copy and paste from another location.
The point remains, within your function, you’d use .ToLower() method to ensure input is lower case as opposed to calling a function to so the same…
function Get-Martians {
[CmdletBinding(ConfirmImpact='Low')]
Param(
[Parameter(Mandatory=$false)][String]$USERNAME = $env:USERNAME
)
Begin { }
Process {
$USERNAME = $USERNAME.ToLower() # ensures value is lower case
$USERNAME
}
End { }
}
Yes. I think that will have to be the method (which I already use) to keep since there is not a Parameter Attribute that I am aware of that will do this.