title: Importing "libraries" in powershell
body: <p>I'm finding myself writing a bunch of related functions dealing with different nouns (clusters, sql servers, servers in general, files, etc.) and put each of these groups of functions in separate files (say cluster_utils.ps1, for example).  I want to be able to "import" some of these libraries in my profile and others in my powershell session if I need them.  I have written 2 functions that seem to solve the problem, but since I've only been using powershell for a month I thought I'd ask to see if there were any existing "best practice" type scripts I could be using instead.</p>
  
  <p>To use these functions, I dot-source them (in my profile or my session)... for example,</p>
  
  <pre><code># to load c:\powershellscripts\cluster_utils.ps1 if it isn't already loaded
  . require cluster_utils    
  </code></pre>
  
  <p>Here are the functions:</p>
  
  <pre><code>$global:loaded_scripts=@{}
  function require([string]$filename){
        if (!$loaded_scripts[$filename]){
             . c:\powershellscripts\$filename.ps1
             $loaded_scripts[$filename]=get-date
       }
  }
  
  function reload($filename){
       . c:\powershellscripts\$filename.ps1
       $loaded_scripts[$filename]=get-date
  }
  </code></pre>
  
  <p>Any feedback would be helpful.</p>