Skip to content

Latest commit

 

History

History

Set-variable-in-caller-scope

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

How to set a variable in the caller scope

Sometimes a function should set a variable in the caller scope. The way to do this depends on how this function is defined and imported.

Functions defined in scripts may use straightforward Set-Variable -Scope 1. This way is not working in module functions.

Functions defined in modules may use less obvious $PSCmdlet.SessionState.PSVariable.Set(). This way is not working in script functions.

Scripts