Variable Scope in exe

Tool: Visual Studio, Visual Studio Code, PSScriptPad, PowerShell Module
Version: 17.9.0
Powershell pro Tools for visual Studio - 1.0

Hi,
the $Script scope does not work in the generated exe. It works in Powershell ISE.

i have variable $SelectedFolderWS = “C:\temp”

the value of the variable is not modified in a function.
function ActioncbFoldWSChange {
$Script:SelectedFolderWS = join-path -path $SelectedFolderWS -childpath $cbFoldWS.selectedItem
}
thank you for your attention

I’ve found the solution. The Scope must be declared when the variable is created, and not just when its contents are modified.
$Script:SelectedFolderWS = “C:\temp”