How to use a global variables file in powershell

Mohammed Abdul-Basith 1 Reputation point

I've been setting up vcheck reports and noticed that all the variables are stored in the global variables.ps1 file, what I'd like to understand is how are these variables referenced in the plugin scripts and other vcheck scripts?
This isn't a vcheck only question though, I'm trying to understand how powershell allows calling variables from an external file, this is something that I dont know how to do and would help me with scripting in general.

Thanks in advance!

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,459 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Andreas Baumgarten 103.9K Reputation points MVP

    Hi @Mohammed Abdul-Basith ,

    maybe this helps to get an idea how global variables are working:

    And an example how to reference to a global variable:


    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Andreas Baumgarten

    0 comments No comments

  2. Rich Matheisen 45,831 Reputation points

    Those are probably "dot-sourced" in the other scripts.

    Something like this:

    . .\variables.ps1        # contains a variable declaration "$x = 1"
    $y = $x + 2
    write-host $y           # value of $y should be 3
    0 comments No comments