79826706

Date: 2025-11-21 15:53:26
Score: 1
Natty:
Report link

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 })
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Santiago
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Peyre