Shared variables

Welcome Forums General PowerShell Q&A Shared variables

This topic contains 3 replies, has 3 voices, and was last updated by

1 year, 4 months ago.

  • Author
  • #74240

    Points: 36
    Rank: Member


    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

    Points: 144
    Helping Hand
    Rank: 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

      Points: 36
      Rank: Member

      Olaf Soyk,

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

  • #74255

    Points: 1,624
    Helping HandTeam Member
    Rank: Community Hero

    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.

The topic ‘Shared variables’ is closed to new replies.