Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I recently ran into the scenario of needing global variables for use within a new module I was creating. This naturally lead to consulting the hive mind that is otherwise known as “The Internet”. Luckily enough, I stumbled across a [post by “GregM”] on the TechNet forums, that proposed an interesting solution.
- 1. Create a module manifest for the module.
- 2. Update the “PrivateData” record in the manifest.
- ...
- FileList = @()
- PrivateData = @{g1 = "string";g2 = "stringTwo";g3 = "stringThree"}
- And that’s all it takes to initialize a global variable within the module scope. Now, on to the manipulation.
- # Retrieving the global variable value and assigning it to a variable
- $test = $MyInvocation.MyCommand.Module.PrivateData['g1']
- # Modify the global variable value
- $MyInvocation.MyCommand.Module.PrivateData['g1'] = $test
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement