Add variables in seperate ps1 (outside project/exe)

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Add variables in seperate ps1 (outside project/exe)

Post by stevens »

To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build: PS Studio, 2017, 5.4.136
32 or 64 bit version of product: 64
Operating system: W2K12R2
32 or 64 bit OS: 64


*** Please add details and screenshots as needed below. ***

Hi,

I'd like to keep variables outside my powershell studio project.
So I entered this in globals.ps1:

#LOAD VARIABLES
$GLobalVariables = $ScriptDirectory + "\config\GlobalVariables.ps1"
Get-Content $GlobalVariables

With f.e.
$ourdomain = 'ourdomain.com' in this globalvariables.ps1

When I add a break after the get-content $globavariables, $ourdomain does not show any value.
Please advise.
J
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: Add variables in seperate ps1 (outside project/exe)

Post by Alexander Riedel »

[Topic moved by moderator]
Alexander Riedel
SAPIEN Technologies, Inc.
cody m

Re: Add variables in seperate ps1 (outside project/exe)

Post by cody m »

In order to use $ourdomain as a variable you are going to need to Dot Source your 'globalvariables.ps1' file, which tells PowerShell to execute the code that is in the file, which will give you access to the variables. Get-Content is also going to read all the content that is in a file and places it in a variable or in your case will dump the files contents into the standard Output stream and since you are using a form, none of this information will be displayed. I would also recommend looking at some of our PowerShell introduction videos that are on YouTube in order to get a better understanding of how PowerShell works.
This topic is 6 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked