Avatar of janhoedt
janhoedt
 asked on

Powershell: keeping all variables in 1 globalvariables.ps1, then load in profile ... but howto exchange these scripts then?

Hi

I'd like to keep all my variables in a GlobalVariables.ps1 which I load in my profile.
All my scripts would then just use $SCCMServer or $SMTPServer instead of full name.

However, this limits the exchange of my scripts, since the scripts won't have the GlobalVariables.ps1.
I could copy GlobalVariables.ps1 to each script I exchange and refer in it via $psscriptroot\globalvariables.ps1 but then I'd need to refer in each of my scripts to this $psscriptroot whereas it is already in my globalvariables.ps1 which is loaded in my profile.
How to address this?

Please advise.
J.
Powershell

Avatar of undefined
Last Comment
Joshua Grantom

8/22/2022 - Mon
Joshua Grantom

That's why I don't customize my profile or add any global variables. If someone else needs to use your script it becomes problematic because they do not have a profile setup like yours.

I would advise to define variables locally in the script as needed, that way colleagues can take advantage of the scripts as well.

Just my 2 cents though.
janhoedt

ASKER
Ok, but then you have to define your variables over and over again in all kinds of scripts ....
ASKER CERTIFIED SOLUTION
Joshua Grantom

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Your help has saved me hundreds of hours of internet surfing.
fblack61