0

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

4

1 回答 1

3

如果您的目标是不允许长格式,您别无选择,只能重命名参数并删除别名。

为了尽量减少对脚本的更改,您可以在函数内创建一个变量,例如

Function Deploy-Citrix {
    [cmdletBinding(SupportsShouldProcess=$True)]
    Param(
        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$ip)

    $ipaddressparam = $ip
    ...
于 2014-09-09T16:25:58.113 回答