0%

Powershell启动脚本

Linux中bash有一个启动的默认配置文件:.bashrc或者.bash_profile,自定义命令以及预配置可以写在那里,但是windows的配置文件在哪里呢?

按照微软官网的说法是按照以下的对应关系,但是实际上是不对的。

Description Path
All Users, All Hosts $PsHome\Profile.ps1
All Users, Current Host $PsHome\Microsoft.PowerShell_profile.ps1
Current User, All Hosts $Home\[My ]Documents\PowerShell\Profile.ps1
Current user, Current Host $Home\[My ]Documents\PowerShell\ Microsoft.PowerShell_profile.ps1

我们可以通过环境变量查看配置文件的路径

Description Name
All Users, All Hosts $PROFILE.AllUsersAllHosts
All Users, Current Host $PROFILE.AllUsersCurrentHost
Current User, All Hosts $PROFILE.CurrentUserAllHosts
Current User, Current Host $PROFILE or $PROFILE.CurrentUserCurrentHost

windows 10 1903版本上的配置文件的实际路径

Description Path
All Users, All Hosts $PsHome\profile.ps1
All Users, Current Host $PsHome\Microsoft.PowerShell_profile.ps1
Current User, All Hosts $Home\Documents\WindowsPowerShell\profile.ps1
Current user, Current Host $Home\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

然后就是按照路径创建配置文件,终于可以写点自定义命令了。