Powershell 保存函数

Powershell save functions

我已经知道如何在powershell 中创建函数了。问题是:如何保存该功能以便将来使用?

当我在 Powershell 中编写 myFunction{3+3} 时,我可以在该会话中使用该函数。

不过,如果我退出powershell再打开它,那个功能就没有了。如何 "save" 函数以便在重新启动 Powershell 后仍能使用它?

将其放入您的 Powershell 配置文件中:

与其在这里解释,不如试试这篇文章:

http://www.howtogeek.com/50236/customizing-your-powershell-profile/

有几种方法:

您可以将其组合成一个模块,然后使用 import-module functions.psm1 将其加载到脚本中或通过使用 ps 配置文件。

您还可以将任何已保存的函数点源到另一个 ps1 ( . .\functions.ps1)。