title: Are Powershell Profile scripts dot-sourced?
body: <p>The <strong>Microsoft.PowerShell_profile.ps1</strong> script I am using creates a lot of variables when it runs. I have set all the variables' scope to "Script", but the variables used in the script never go out-of-scope.</p>
  
  <p>I would like the variables to go out-of-scope once the script is done running and control is handed over to me.</p>
  
  <p>If I compare the number of global, local, and script variables I have, I come up with the same number.</p>
  
  <p>Example:</p>
  
  <pre><code># Profile script does what it does.
  
  Get-Variable -Scope Global | Measure-Object
  Get-Variable -Scope Local  | Measure-Object
  Get-Variable -Scope Script | Measure-Object
  
  Output:
  60
  60
  60
  </code></pre>
  
  <p>Currently, I am capturing a snapshot of the variables at the beginning of my profile script, then removing any new variables at the end.</p>
  
  <p>Example:</p>
  
  <pre><code>$snapshotBefore = Get-Variable
  $profileVar1 = 'some value'
  $profileVar2 = 'some other value'
  $snapshotAfter = Get-Variable
  
  # Compare before and after, and create list of new variables.
  
  Remove-Variable $variablesToRemove
  </code></pre>