Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 对于包含空格字符的值,设置别名失败_Powershell_Alias - Fatal编程技术网

Powershell 对于包含空格字符的值,设置别名失败

Powershell 对于包含空格字符的值,设置别名失败,powershell,alias,Powershell,Alias,我想用⍋ 要按升序排序,请使用⍒ 按降序排序 我成功地设置了⍋ 作为排序的别名(默认为升序): I设置失败⍒ 要使用别名进行降序排序,请执行以下操作: Set-Alias -Name ⍒ -Value Sort-Object -Descending 以下是我收到的错误消息: Set-Alias : A parameter cannot be found that matches parameter name 'Descending'. At line:1 char:38 + S

我想用⍋ 要按升序排序,请使用⍒ 按降序排序

我成功地设置了⍋ 作为排序的别名(默认为升序):

I设置失败⍒ 要使用别名进行降序排序,请执行以下操作:

Set-Alias -Name ⍒ -Value Sort-Object -Descending
以下是我收到的错误消息:

Set-Alias : A parameter cannot be found that matches parameter name 'Descending'.
    At line:1 char:38
    + Set-Alias -Name ⍒ -Value Sort-Object -Descending
    +                                      ~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-Alias], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.SetAliasCommand

任何帮助都将不胜感激。

您不能设置包含参数的别名。 您需要创建一个包装cmdlet的函数

函数排序对象降序
{
[别名(”⍒")]
param(
[参数(位置=0)]
[对象[]]
$Property,
[开关]
$区分大小写,
[字符串]
$Culture,
[开关]
$Unique,
[参数(ValueFromPipeline)]
[PSObject]
$InputObject
)
开始{
试一试{
$scriptCmd={排序对象-降序@PSBoundParameters}
$steppablePipeline=$scriptCmd.GetSteppablePipeline()
$steppablePipeline.Begin($PSCmdlet)
}抓住{
扔
}
}
过程{
请尝试{$steppablePipeline.Process($)}catch{throw}
}
结束{
请尝试{$steppablePipeline.End()}捕获{throw}
}
}

您只能为cmdlet或函数设置别名…而不是带有参数的cmdlet/函数。您将需要创建一个包装函数和别名。[grin]的确,@Lee_Dailey。密切相关:-但是如果您希望别名接受管道输入,这是一种方法。@mklement0-the
.GetSteppablePipeline()
这些东西对我来说是新的……我要去看书了……[咧嘴笑]@Lee_Dailey:看到了吗
Set-Alias : A parameter cannot be found that matches parameter name 'Descending'.
    At line:1 char:38
    + Set-Alias -Name ⍒ -Value Sort-Object -Descending
    +                                      ~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-Alias], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.SetAliasCommand