Global variable in PowerShell module

This topic contains 2 replies, has 2 voices, and was last updated by  Pradeep Arora 2 weeks ago.

  • Author
    Posts
  • #83660

    Bojan Zivkovic
    Participant

    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.

  • #83672

    Pradeep Arora
    Participant

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

  • #83674

    Pradeep Arora
    Participant

    Then I found this on the web: Use PowerShell to Persist 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')
    

You must be logged in to reply to this topic.