开发者

referencing powershell files in main file

I have a powershell file with some utility functions.

Is it possible to reference this utility file in another powershell file and use the utility cla开发者_开发知识库sses from it? If so, how can this be done?


You can “dot-source” a script to run it in the current scope. If your utility script is something like utils.ps1, then you can do

. .\utils.ps1

and all functions that are declared in the script are available to you. This doesn't stop with functions, though, script-scoped variables as well and all code in the script will actually run, so be careful whether that's really what you want.

A nicer option, but maybe a bit overkill for a few utility functions, would be a module containing said functions. With modules you have finer-grained control over what gets imported and what parts are private to the module.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜