I recently had a couple of administrators who were upset that PowerShell doesn’t have a way to "include" files in a script. Basically, the idea is that you make a script which contains a bunch of commonly-used functions, and then "include" those inside other scripts. That way, the other scripts can take full advantage of the functions, while keeping the functions contained within a single, easy-to-edit file.
Guess what? PowerShell totally includes this capability. It just doesn’t provide an "include" keyword. So if your "function library" script is named c:\libs\mylib.ps1, just drop this in the beginning of your scripts:
. c:\libs\mylib.ps1
Poof! The library script is executed within your script’s scope, and all of your library functions become available within the script. Do this with as many scripts as you like, but be sure to do so at the TOP of your script; that will ensure any functions are loaded into memory and made available before they’re needed by your script.
(BTW, rumor has it that v2 of PowerShell may offer some cool new way of more formally "including" scripts inside other scripts – stay tuned, and check out Windows PowerShell v2.0: TFM for ongoing updates to v2’s functionality).
We also can use relative path:
. ./mylib.ps1