title: Dot Sourced Variables VS Global Variables
body: <p>I have two ways of referencing script variables from a separate script file. Here are two basic examples:</p>
  
  <p><strong>1. Dot Source</strong><br>
  Variables.ps1</p>
  
  <pre><code>$Source = "source"  
  $Destination = "dest"
  </code></pre>
  
  <p>Execute.ps1</p>
  
  <pre><code>. .\Variables.ps1  
  Copy-Item -Path $Source -Destination $Destination -Force
  </code></pre>
  
  <p><strong>2. Global Variable</strong><br>
  Variables.ps1</p>
  
  <pre><code>$Global:Source = "source"  
  $Global:Destination = "dest"
  </code></pre>
  
  <p>Execute.ps1</p>
  
  <pre><code>.\Variables.ps1  
  Copy-Item -Path $Source -Destination $Destination -Force
  </code></pre>
  
  <p>I have done research but have yet to find a definitive reason as to use one over the other. Are there limitations or cautions I should exercise when using these methods? Any input is greatly appreciated. Thank you for your time.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>@mklement0 gave a great answer as to why to use dot-sourcing over global variables. I would love to still keep this discussion open. If there is another point of view, or an explanation as to when using global variables is more beneficial, I would enjoy hearing it and up-voting accordingly. Thank you.</p>