A PowerShell module for importing functions.
Install-Module PsImport
-
Supports wildcards:
(Import * -from '/relative/path/to/script.ps1').ForEach({ . $_.ScriptBlock })
Will load functions from the file into current script scope.
-
Importing from many files at once:
(Import * -from '/relative/path/to/fileNamedlikeabc*.ps1').ForEach({ . $_.ScriptBlock })
Will load all functions from .ps1 files that look like fileNamedlikeabc
-
Import a function(s) from same repo
Cd GitHubRepo (Import funcName1, funcName2).ForEach({ . $_.ScriptBlock })
Will only load functions funcName1 and funcName2 from fileNameb.
*if you are sure no other file is named fileNameb is in the repo.
-
Import a function(s) from a remote script
(Import funcName -from https://example.com/MyRemoteScript.ps1).ForEach({ . $_.ScriptBlock })
-
more ?
((ls ./Private -Filter "*.psm1" -Recurse).FullName | Get-Function)
-
Fix edge cases when parsing files.
Sometimes it does not find all function declarations in file $filepath.
[PsImport]::ParseFile($Filepath)
For now it Works as expected only when there is a clear newline char (ie: "`n") between each function in the file.
-
Remove (/ Find a workarround) for the '.ForEach({ . $_ })' that is used in the import syntax.
If you would like to contribute to psimport, please feel free to submit a pull request on GitHub. We welcome contributions of all kinds, from bug fixes to new features.
This module is licensed under the MIT License.