powershell - 永久点源文件?

标签 powershell dot-source

我一直在使用 Custom-Powershell-Script。我可以简单地对文件进行点源,但我必须在每个 session 中执行此操作。

. .\Hello-World.ps1

有没有办法永久点源文件?我不想一遍又一遍地这样做。

最佳答案

首先检查您的分析器是否存在。

Test-Path $profile

如果它返回False,我们必须创建它们。在提升模式下运行 PS。

New-Item -path $profile -type file –force 

所以它会要求确认。

从路径中打开名为 Microsoft.Powershell_profile.ps1 的文件,然后直接在其中添加条目,如下所示:

. .\Hello-World.ps1

完成后,保存并重新启动。如果再次打开它,您应该能够看到 Hello-World.ps1 中存在的点源函数

默认情况下$profile路径应该是:

C:\Users\用户名\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

希望有帮助。

关于powershell - 永久点源文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48377955/

相关文章:

bash - 在调用另一个脚本时使用点或 "source"- 有什么区别?

windows - 如何在 PowerShell 中的子文件夹中点源函数

批处理文件中的 Powershell - 如何转义元字符?

电源外壳 |将数组元素传递给函数

powershell - 在 PowerShell 中,如何在文件中定义函数并从 PowerShell 命令行调用它?

powershell - 点源文件中的 PSScriptRoot 如何工作?

新实例中的 PowerShell 启动脚本

c# - C# 托管的 Powershell 中的内存泄漏

powershell - TFS vNext build agent安装