Windows PowerShell 设置命令别名永久生效
PowerShell Windows 大约 1636 字当前会话生效
Set-Alias -Name k -Value kubectl
设置永久生效
PowerShell 配置文件位置
文件不一定存在
$profile
$PsHome
$profile.AllUsersAllHosts
$profile.AllUsersCurrentHost
$profile.CurrentUserAllHosts
$profile.CurrentUserCurrentHost
输出
PS C:\Users\fendoudebb> $profile
C:\Users\fendoudebb\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
PS C:\Users\fendoudebb> $PsHome
C:\Windows\System32\WindowsPowerShell\v1.0
PS C:\Users\fendoudebb> $profile.AllUsersAllHosts
C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
PS C:\Users\fendoudebb> $profile.AllUsersCurrentHost
C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
PS C:\Users\fendoudebb> $profile.CurrentUserAllHosts
C:\Users\fendoudebb\Documents\WindowsPowerShell\profile.ps1
PS C:\Users\fendoudebb> $profile.CurrentUserCurrentHost
C:\Users\fendoudebb\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
创建配置文件
PowerShell
中输入如下命令:
if (!(Test-Path -Path $PROFILE)) {
New-Item -ItemType File -Path $PROFILE -Force
}
设置别名
打开配置文件添加内容:
语法:
function 别名 { 原命令 @Args }
示例:
function k { kubectl @Args }
直接在命令行设置
echo "function k { kubectl @Args }" >> $profile
可能的错误
错误信息
File xxx\Microsoft.PowerShell_profile.ps1 cannot be loaded because running scripts is disabled on this system
错误原因
Windows
系统为了防止恶意脚本自动执行,故默认不允许自动运行脚本。
解决方法
获取执行策略
Get-ExecutionPolicy
输出:如果是RemoteSigned
,则不用再更改执行策略。
PS C:\Users\fendoudebb> Get-ExecutionPolicy
RemoteSigned
以管理员身份,在PowerShell
中执行Set-ExecutionPolicy RemoteSigned
,即可。
Set-ExecutionPolicy RemoteSigned
参考
https://docs.microsoft.com/zh-cn/powershell/module/microsoft.powershell.core/about/about_profiles
阅读 761 · 发布于 2022-08-15
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看
换一批
-
Arthas 使用 trace 查找耗时操作和调用链路阅读 7574
-
面试题:HashMap 和 Hashtable 的区别阅读 1963
-
建站必备网址阅读 3099
-
VisualVM 监控注册成 Windows 服务的 Tomcat 之 jstatd 方式二阅读 1628
-
软考-系统架构设计师:逆向工程阅读 1804
-
Test.class found in top-level directory (unnamed package not allowed in module)阅读 3837
-
Nginx 开启 HTTP2.0阅读 2162
-
不同标签页同步用户登录状态阅读 1207
-
Spring 事务失效的几种场景阅读 1152
-
Android 使用 tools schemas 预览 UI阅读 1913