美文网首页
使用powershell profile文件添加永久别名AIia

使用powershell profile文件添加永久别名AIia

作者: mudssky | 来源:发表于2020-03-13 03:45 被阅读0次

使用powershell profile文件添加永久别名AIias

​ 前几天powershell7.0版本更新了,上个版本6.0的时候没有怎么使用,7.0据说提升比较大,所以我就安装了。

​ 看了更新文档,个人印象中平时会用的比较多的是三目运算符的添加,还有foreach支持并行模式,这样对于提高执行效率还是很有帮助的ForEach-Object -Parallel

​ 还有一个比较实用,就是powershell core有自动更新功能了。

Parallel running script block . Beginning with PowerShell 7.0, a third parameter set is   available that runs ea     ch script block in parallel. There is a `-ThrottleLimit` parameter that   limits the number of parallel scripts ru     nning at a time. As before, use the `$_` variable to   represent the current input object in the script block. Use      the `$using:` keyword to pass variable   references to the running script.

    By default, the parallel scriptblocks use the current working directory of the caller that started   the parallel      tasks

​ 微软在github开源的powershell和win10自带的还是有点区别的,自带的还停留在6.0版本。并且有一些别名是不一样的,比如说ise,win10自带的powershell编辑器,自带的补全功能还是相当好用的。

​ powershell core是跨平台的,因此没有添加windows平台特有内容的别名。默认只能用powershell_ise.exe来打开。所以我们需要手动添加别名。

​ 使用set-alias方法可以定义别名,或者使用new-alias方法创建一个新别名,但是在powershell窗口执行的话只在一个会话内有效,把窗口关闭再打开就失效了。

​ 类似于linux,可以powershell启动之前会自动执行一个脚本,就是$profile,这个环境变量就是启动脚本的位置,我们在那里创建这个ps1文件,那么powershell在启动时就会调用。我们在这个文件里进行设置就行了。

​ 首先在powershell里输入$profile,查看profile文件的位置,然后打开,加入下面这句话即可

set-alias ise powershell_ise.exe

相关文章

网友评论

      本文标题:使用powershell profile文件添加永久别名AIia

      本文链接:https://www.haomeiwen.com/subject/zjlzjhtx.html