Reuse a Powershell function
Reuse a Powershell function

Very interesting article found in the Technet Blog

To use the functions contained in the include.ps1 script, you can (…) dot-source the script. This is seen in the useInclude.ps1 script.

. "c:\fso\include.ps1" 
addone -intIn 3 
addTwo -intIn 3

When the script runs, both functions are available to the script, and can be called directly from the body of the script as if they had been copied and pasted into the script. The two functions from the Include.ps1 script are not on the function drive prior to execution of the UseInclude.ps1 script. After the script completes, they still are not on the function drive. The only way to have access to the functions inside the Windows PowerShell console is to dot-source them directly into the Windows PowerShell console

<>

My Powershell script categories


References

http://blogs.technet.com/b/heyscriptingguy/archive/2010/08/10/how-to-reuse-windows-powershell-functions-in-scripts.aspx

http://blogs.technet.com/b/heyscriptingguy/archive/2010/08/09/how-do-i-use-a-windows-powershell-script-containing-functions.aspx

Reuse a Powershell function

4 thoughts on “Reuse a Powershell function

Leave a Reply to Nicolas HAHANG Cancel reply

Your email address will not be published.