title: How can I re-use/import script code in PowerShell scripts?
body: <p>I have to create a PowerShell script which does exactly same thing as my <a href="https://stackoverflow.com/questions/26706941/convert-xml-to-specific-json-structure-with-powershell/26707226#26707226">previous script</a>, but this time I have to read a CSV file instead of an XML file. My plan is to create a PowerShell script which has common functions required for both scripts and re-use this common script file in both main files.</p>
  
  <p>Suppose I create 2 main files in 2 directories in <code>C:\</code> drive and keep my common file and other 3<sup>rd</sup> party libraries in a folder of <code>D:\</code> drive, e.g. <code>C:\script_1_folder\Script1.ps1</code>, <code>C:\script_2_folder\Script2.ps1</code> and common file and 3<sup>rd</sup> party libraries will be in <code>D:\script_common</code>.</p>
  
  <ol>
  <li><p>How do I call\re-use common file in my main files (how to get the path, do I have to create an instance of common file and how do I use it)</p>
  
  <p>What is the difference between </p>
  
  <pre><code>$script_path    = $myinvocation.invocationname;      
  $script_folder  = split-path $script_path -parent;
  write-host  $script_folder  
  $script_name    = split-path $script_path -leaf;      
  $current_folder = [system.io.directory]::getcurrentdirectory()    
  [system.io.directory]::setcurrentdirectory($script_folder)
  Set-Location $script_folder
  add-type -path ".\AlexFTPS-1.1.0\AlexPilotti.FTPS.Client.dll"
  </code></pre>
  
  <p>and  </p>
  
  <pre><code>$path = (split-path $MyInvocation.MyCommand.Path) 
  $loggerPath = $path + "\Logger\release\Logger.ps1";
  .$loggerPath; 
  $logger = Logger;   
  $logger.load($path + "\Logger\config\log4ps.xml","log.log"); 
  </code></pre>
  
  <p>and what is the best way to do it with regard to my problem?</p></li>
  <li><p>How do I create a temp folder in windows temp folder?</p></li>
  </ol>