Powershell 别名位置

Powershell aliases location

如果我 运行 PowerShell 在工作并且 运行 命令 alias,这就是我得到的:

这些别名存储在哪里?我如何将(我自己的)永久别名添加到该列表?

来自Get-Alias文档:

The Get-Alias cmdlet gets the aliases in the current session. This includes built-in aliases, aliases that you have set or imported, and aliases that you have added to your Windows PowerShell profile.

您可以使用 Set-Alias 来设置您自己的。例如。来自文档:

PS C:\> Set-Alias -Name list -Value get-childitem

  • 内置 - 不需要修改这些。
  • 设置或导入 - 您可以如上所述使用Set-Alias。当您关闭会话时,这将丢失。您还可以在会话结束时 Export-Alias,在新会话开始时 Import-Alias
  • Windows PowerShell Profile - 我建议使用此方法,因为它会在您每次开始新会话时自动 运行。该文档详细介绍了不同的配置文件及其范围(shell 或 ISE 或两者兼而有之?所有用户还是只有您?)

    使用 PowerShell 配置文件的最简单方法:

    • 转到C:\Users\user\Documents\WindowsPowerShell
      如果 WindowsPowerShell 文件夹不存在,请创建它。
    • 创建包含您的代码的新文件 Profile.ps1。示例如下。

Set-Alias -Name eg -Value www

Function www {
    cd "C:\Users\user\Documents\Projects"
}