Shared variables

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of Vandrey Trindade Vandrey Trindade 3 weeks, 3 days ago.

  • Author
    Posts
  • #74240
    Profile photo of Vandrey Trindade
    Vandrey Trindade
    Participant

    Hi,

    I'm starting to create a shared_variables.ps1 file where I want to store general variables that I will use in other scripts.
    Then on the other scripts I just call that file and it imports all the variables to it.

    I just want an idea of how to do it on PowerShell... my friend did it on Bash and it worked nice.

  • #74251
    Profile photo of Olaf Soyk
    Olaf Soyk
    Participant

    If you like to have it all your Powershell sessions you could put it to your personal profile or to the all users profile.

    • #74266
      Profile photo of Vandrey Trindade
      Vandrey Trindade
      Participant

      Olaf Soyk,

      Nevermind... Don Jones already gave me the answer below.
      Thanks for you two!

  • #74255
    Profile photo of Don Jones
    Don Jones
    Keymaster

    You could also dot-source it. That said, this is kind of a horrible practice. PowerShell isn't Bash, and what you're doing is loading up the global scope (which isn't even a concept in Bash) and setting up plenty of potential conflicts. Applying Bash-style techniques in PowerShell is just going to make it harder to use PowerShell the way it was designed.

You must be logged in to reply to this topic.