# Global variable in PowerShell module

**URL:** <https://forums.powershell.org/t/global-variable-in-powershell-module/9655>\
**Category:** PowerShell Help\
**Created:** [November 6, 2017, 7:02am UTC](https://forums.powershell.org/t/global-variable-in-powershell-module/9655 "2017-11-06T07:02:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bojan-zivkovic](https://avatars.discourse-cdn.com/v4/letter/b/7feea3/32.png) [@bojan-zivkovic](https://forums.powershell.org/u/bojan-zivkovic)\
**Post date:** [November 6, 2017, 7:02am UTC](https://forums.powershell.org/t/global-variable-in-powershell-module/9655/1 "2017-11-06T07:02:06Z")

</div>

Hi, I wrote more than 20 advanced functions to automate installation/configuration process of document management platform (OpenText Documentum xCP). One of them is “input” function for many others since it returns an object containing 3 crucial properties (docbroker host name, docbase name and global registry password). Can I call this “main” function only once, store returned object into global variable and then just use property of that variable in other functions?

i.e. $global:dfc = Get-DFCParameter -xCP1ComputerName VMContentServer  
from some other function:  
$Docbroker = $dfc.docbrokerhostname  
$Docbase = $dfc.docbasename  
$GlobalRegistryPassword = $dfc.globalregistrypassword

Note: I posted similar question last year but no one answered. More luck this time I hope.

---

<div class="post-metadata">

**Author:** ![pradeeparoratx](https://avatars.discourse-cdn.com/v4/letter/p/f6c823/32.png) [@pradeeparoratx](https://forums.powershell.org/u/pradeeparoratx)\
**Post date:** [November 6, 2017, 9:10am UTC](https://forums.powershell.org/t/global-variable-in-powershell-module/9655/2 "2017-11-06T09:10:58Z")

</div>

One answer would be to create your own Registry hive and set keys in there.

---

<div class="post-metadata">

**Author:** ![pradeeparoratx](https://avatars.discourse-cdn.com/v4/letter/p/f6c823/32.png) [@pradeeparoratx](https://forums.powershell.org/u/pradeeparoratx)\
**Post date:** [November 6, 2017, 9:15am UTC](https://forums.powershell.org/t/global-variable-in-powershell-module/9655/3 "2017-11-06T09:15:40Z")

</div>

Then I found this on the web: Use PowerShell to Persist Environment Variables  
[https://trevorsullivan.net/2016/07/25/powershell-environment-variables/](https://trevorsullivan.net/2016/07/25/powershell-environment-variables/)  
cut& paste from there below:

```
### Use the variable syntax to create a new environment variable
$env:FirstName = 'Trevor'
### Use the built-in env: PSDrive
New-Item -Path env:\LastName -Value Sullivan
### Set an environment variable using the System.Environment .NET class
[System.Environment]::SetEnvironmentVariable('DOCKER_HOST', 'docker.artofshell.com')
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:37pm UTC](https://forums.powershell.org/t/global-variable-in-powershell-module/9655/4 "2024-05-16T20:37:17Z")

</div>


