如何永久删除默认的 Powershell 别名?

Nat*_*ley 37 powershell

由于某些未知原因,开发人员将“curl”作为 的别名包含在内Invoke-WebRequest,即使它与 curl 的正确实现不兼容,这意味着当我尝试发出 curl 请求时,它会妨碍我。我可以使用 删除别名Remove-Item alias:curl,但下次启动 Powershell 时,别名已返回。有没有办法永久删除它而不必每次启动时都运行脚本?

meg*_*orf 50

如果您已有 Powershell 配置文件,请跳过此步骤:

New-Item $profile -force -itemtype file
Run Code Online (Sandbox Code Playgroud)

然后编辑您的个人资料:

notepad $profile
Run Code Online (Sandbox Code Playgroud)

向其中添加以下行:

remove-item alias:curl
Run Code Online (Sandbox Code Playgroud)

使用以下命令保存、关闭记事本并重新加载配置文件,或关闭并打开 Powershell 以应用配置文件:

. $profile
Run Code Online (Sandbox Code Playgroud)

  • 谢谢。我必须说,powershell 开发人员没有考虑清楚这一点很烦人,迫使我们现在必须以这种方式解决这个问题。 (2认同)
  • 第一步始终可以被跳过。我刚刚这样做了,然后弹出一个窗口,询问我是否要创建该文件。 (2认同)

bea*_*ker 6

我会坚持使用curl.exe而不仅仅是curl. 这种方法不依赖于使用特定配置文件运行的 PowerShell(并且可以使用-NoProfileswitch在根本没有配置文件的情况下运行 PowerShell )。