如何永久使用Powershell为可执行文件添加别名?

如何永久使用Powershell为可执行文件添加别名?,powershell,Powershell,在当前Powershell会话中创建和运行别名有效 Windows PowerShell Copyright (C) 2013 Microsoft Corporation. All rights reserved. PS C:\Windows\system32> new-item alias:eadt -value "C:\adt-bundle-windows-x86_64-20140702\eclipse\eclipse.exe" CommandType Name

在当前Powershell会话中创建和运行别名有效

Windows PowerShell
Copyright (C) 2013 Microsoft Corporation. All rights reserved.

PS C:\Windows\system32> new-item alias:eadt -value "C:\adt-bundle-windows-x86_64-20140702\eclipse\eclipse.exe"

CommandType     Name                                               ModuleName
-----------     ----                                               ----------
Alias           eadt -> eclipse.exe


PS C:\Windows\system32> eadt
但在新会话中失败:

PS C:\Windows\system32> eadt
eadt : The term 'eadt' 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
+ eadt
+ ~~~~
    + CategoryInfo          : ObjectNotFound: (eadt:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\Windows\system32>

您应该在配置文件中保存别名(如Linux中的.bashrc)。看一看,选择你的一个

$Profile
var为您提供配置文件的路径

它存在4个不同的profil文件,由以下给出:

$profile.AllUsersAllHosts
C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1

$profile.AllUsersCurrentHost
C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShellISE_profile.ps1

$profile.CurrentUserAllHosts
C:\Users\JPB\Documents\WindowsPowerShell\profile.ps1

$profile.CurrentUserCurrentHost
C:\Users\JPB\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1