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


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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Joshua GrantomSenior Systems AdministratorCommented:
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.
janhoedtAuthor Commented:
Ok, but then you have to define your variables over and over again in all kinds of scripts ....
Joshua GrantomSenior Systems AdministratorCommented:
Correct, you want to try and keep each script as independent as possible. Increasing dependencies just increases points of failure.

Unless you want to deliver multiple scripts as a tool set or collection of scripts, then you can use your globalvariables.ps1 and $psscriptroot like you mentioned and just document that the scripts must stay together for it to work correctly. Not really a way around it unless you want to put your globalvariables.ps1 on a network share that everyone can read

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.