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

时间:2014-07-20 14:30:08

标签: 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                                               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>

1 个答案:

答案 0 :(得分:7)

您应该在配置文件中保存别名(例如Linux中的.bashrc)。 Hava希望About_profile选择你的。

$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