首页 > 解决方案 > powershell 不能使用删除别名

问题描述

当我进入 PowerShell 时:

Remove-Alias -Name someAlias

此错误显示:

Remove-Alias : The term 'Remove-Alias' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Remove-Alias -Name someAlias
+ ~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Remove-Alias:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

注意: someAlias 已经在我的别名列表中,我检查了这个。

标签: powershell

解决方案


Powershell 5.1文档New-Alias

备注 要创建新别名,请使用 Set-Alias 或 New-Alias。要更改别名,请使用 Set-Alias。要删除别名,请使用 Remove-Item。

所以在 Powershell 5.x 下你必须使用Remove-Item. 如上评论所述,Remove-Alias仅 PowerShell 6 支持。

检查this stackoverflow answer如何通过删除别名Remove-Item


推荐阅读