title: In Powershell, how to set variable values within a function and have that value available in the parent scope?
body: <p>I am trying to set the values for some variables using a function. My code is below:</p>
  
  <pre><code>$BackupFile = $null
  $TaskSequenceID = $null
  $OSDComputerName = $null
  $capturedWimPath = $null
  
  Function Set-OsToBuild 
  {
    switch ($OsToBuild)
    {
      "Win7x64"
          { 
              $BackupFile = "Win7x64-SP1.wim"
              $TaskSequenceID = "WIN7X64BC"
              $OSDComputerName = "Ref-Win7x64"
              $capturedWimPath = "$($PathToMdtShare)\Captures\$BackupFile"
          }
    }
  }
  </code></pre>
  
  <p>The problem is that these values for $BackupFile, $TaskSequenceID, $OSDComputerName and $capturedWimPath are blank/null outside of this function. </p>
  
  <p>What is the proper way to do this? I want to set these values within this function and have those values available later on in the script, in the parent scope.</p>