The variables are created in your function's local-scope. Those variables are deleted when your function is done.
Global:
The scope that is in effect when Windows PowerShell
starts. Variables and functions that are present when
Windows PowerShell starts have been created in the
global scope. This includes automatic variables and
preference variables. This also includes the variables, aliases,
and functions that are in your Windows PowerShell
profiles.
Local:
The current scope. The local scope can be the global
scope or any other scope.
Script:
The scope that is created while a script file runs. Only
the commands in the script run in the script scope. To
the commands in a script, the script scope is the local
scope.
Source: about_Scopes
If you need the variables to be available for the script, then write them to the script scope.
$BackupFile = $null
$TaskSequenceID = $null
$OSDComputerName = $null
$capturedWimPath = $null
Function Set-OsToBuild
{
switch ($OsToBuild)
{
"Win7x64"
{
$script:BackupFile = "Win7x64-SP1.wim"
$script:TaskSequenceID = "WIN7X64BC"
$script:OSDComputerName = "Ref-Win7x64"
$script:capturedWimPath = "$($PathToMdtShare)\Captures\$BackupFile"
}
}
}
If you would like to keep the values for whole sessions (until you close the powershell-process), then you should use the global scope.
$global:BackupFile = $null
$global:TaskSequenceID = $null
$global:OSDComputerName = $null
$global:capturedWimPath = $null
Function Set-OsToBuild
{
switch ($OsToBuild)
{
"Win7x64"
{
$global:BackupFile = "Win7x64-SP1.wim"
$global:TaskSequenceID = "WIN7X64BC"
$global:OSDComputerName = "Ref-Win7x64"
$global:capturedWimPath = "$($PathToMdtShare)\Captures\$BackupFile"
}
}
}