Advanced function - store function output in global variable

Welcome Forums General PowerShell Q&A Advanced function - store function output in global variable

This topic contains 1 reply, has 2 voices, and was last updated by

2 years, 7 months ago.

  • Author
  • #58839

    Topics: 32
    Replies: 40
    Points: 1
    Rank: Member

    Hi, I have myriad advanced functions, some of which heavily rely on the "main" advanced function which reads a .properties file and extracts some values by using regular expressions. I implemented the "main" advanced function to collect values from .properties file and return object with these values as properties.

    Is there any way to call this main advanced function only once and store its output (custom object in my case) in global variable thus I could reference to needed value in other functions by variable.nameofproperty instead of calling function again and again from other functions.

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

  • #58861

    Topics: 8
    Replies: 1191
    Points: 644
    Helping Hand
    Rank: Major Contributor

    I asked a similar question regarding session information persisting versus having to call the same function over and over. Take a look at Warren's response and InfoBlox implmentation:

The topic ‘Advanced function - store function output in global variable’ is closed to new replies.