title: What's the proper use of scoped variables in powershell?
body: <p>The way I've been writing code is that I've been making separate ps1 files to do specific tasks.  In doing so I noticed that a script in one file has access to the variables of the calling script.  </p>
  
  <p>For my limited purposes, I don't think I'll ever want to have globals as I want each ps1 file to act as a function which is passed the arguments it needs.  </p>
  
  <p>Should I be defining a scope for every variable I create?  Is there a way to force all variables in a ps1 file to be local in scope?  Or do I need to set the scope on each variable?</p>
  
  <p>EDIT (Untested simplified code to demonstrate):</p>
  
  <p>The second file will print $month from the first file.  This means it's a global and not local just to file1.ps1.  I don't want globals as I'd rather pass what I need the other scripts need.  Should file2.ps have been defined as a function to prevent this? </p>
  
  <pre><code>file1.ps1:
  
  $date = Get-Date
  $month = $date.Month
  
  ./file2.ps1
  
  ---------------------
  file2.ps1:
  
  write-host $month
  
  =================================
  </code></pre>