在当前Powershell会话中创建和运行别名是有效的,
Windows PowerShell
Copyright (C) 2013 Microsoft Corporation. All rights reserved.
PS C:Windowssystem32> new-item alias:eadt -value "C:adt-bundle-windows-x86_64-20140702eclipseeclipse.exe"
CommandType Name ModuleName
----------- ---- ----------
Alias eadt -> eclipse.exe
PS C:Windowssystem32> eadt
但在新会话中失败:
PS C:Windowssystem32> 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:Windowssystem32>
您应该将别名保存在配置文件中(就像Linux中的.bashrc一样)。看一下About_profile来选择你的。
$Profile
var给出了配置文件的路径。
它存在4个不同的配置文件:
$profile.AllUsersAllHosts
C:WindowsSystem32WindowsPowerShellv1.0profile.ps1
$profile.AllUsersCurrentHost
C:WindowsSystem32WindowsPowerShellv1.0Microsoft.PowerShellISE_profile.ps1
$profile.CurrentUserAllHosts
C:UsersJPBDocumentsWindowsPowerShellprofile.ps1
$profile.CurrentUserCurrentHost
C:UsersJPBDocumentsWindowsPowerShellMicrosoft.PowerShellISE_profile.ps1