Using @Santiago Squadron answer I now have a forth option. Executing script in the module context is a powerful trick. I have to think about it. Life would be a lot easier if it was possible to have name space, or getter/setter for regular variables.
$value = 0
function doCheck {
write-host $value
$script:value += 1
}
Export-ModuleMember -Function 'doCheck'
[CmdletBinding()]
param ( )
begin {
import-module -Name '.\myModule.psm1' -Force
$myModule = Get-Module myModule
}
process { }
end {
write-host (. $myModule { $value })
. $myModule { $value += 1 }
myModule\doCheck
write-host (. $myModule { $value })