Question:
I’m using a function which creates some variables I’d like to use after the function has processed.
I’ve tried accessing them directly but I can’t. How would I go about doing this?
Answer:
Variables inside functions don’t survive after the function has been run. If you want to access them after the function has processed, prefix them with a scope modifier.
1 2 3 4 5 |
PS> function test-var{ $script:var='foo' } PS> test-var # excute the function PS> $var #print var foo |
Type this in your console for more information:
1 2 |
PS> Get-Help about_Scopes |