Reputation: 3524
How can i use alias only when i call my cmdlet function ?
This is my code
Function Deploy-Citrix {
[cmdletBinding(SupportsShouldProcess=$True)]
Param(
[Parameter(Mandatory=$true)]
[Alias("component")]
[ValidateNotNullOrEmpty()]
[string]$componentparam,
[Parameter(Mandatory=$true)]
[Alias("ip")]
[ValidateNotNullOrEmpty()]
[string]$ipaddressparam,
)
In this case for the second parameter for example, i can use the alias -ip
but i can also use -ipaddressparam
.
Deploy-citrix -componentparam "toto" -ipaddressparam "172.22.0.100"
Deploy-citrix -component "toto" -ip "172.22.0.100"
I can use both, but i want to disable the first one, i want to have alias only.
I know i can rename my variable, but i don't want to touch them in the whole script.
How can i achieve that?
I'm using Powershell V4.0
Thanks
Upvotes: 0
Views: 1678
Reputation: 8019
If your goal is disallow the long form, you have no choice but to rename the parameter and remove the alias.
To minimize changes to your script, you can create a variable inside the function, e.g.
Function Deploy-Citrix {
[cmdletBinding(SupportsShouldProcess=$True)]
Param(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$ip)
$ipaddressparam = $ip
...
Upvotes: 4