下面是在powershell中创建别名的指南,我运行了以下命令:
Set-Alias rush-enable "Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass"这就设置了别名。但是,当我运行别名时,我遇到了一个错误。
PS C:\example> rush-enable
rush-enable : The term 'Set-ExecutionPolicy -Scope Process
-ExecutionPolicy Unrestricted' 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
+ rush-enable
+ ~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Set-ExecutionPo.
..cy Unrestricted:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException但是,对它自己的命令运行很好:
PS C:\example> Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted
PS C:\example> 我是不是遗漏了什么?如何将命令格式化为别名?
发布于 2022-01-11 17:33:55
根据文献资料
可以为cmdlet、脚本、函数或可执行文件分配别名。 不能为命令及其参数分配别名。例如,可以为
Get-Eventlogcmdlet分配别名,但不能将别名分配给Get-Eventlog -LogName System命令。
这大概是一种避免对存在于别名上且在调用别名时传递的参数进行消歧的方法。
因此,你有两个选择:
Enable-Rush的函数中(如果您关心的话,请注意PowerShell可接受命名方案 )。在您的例子中,这看起来应该是:function Enable-Rush {
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
}为了坚持它,把它放在一个$PROFILE中。根据系统的不同,您可能需要对$PROFILE或更改PowerShell系统执行策略进行数字签名,以允许系统生成的PowerShell脚本在启动PowerShell进程时执行。
https://stackoverflow.com/questions/70670937
复制相似问题