Solved

execute a file containing variables to be initialized at the start of another script

Posted on 2012-03-14
4
280 Views
Last Modified: 2012-03-26
Hello,

Is it possible to execute a file containing variables to be initialized at the start of another script?

If yes, how?

Thanks

regards

bibi
0
Comment
Question by:bibi92
  • 2
  • 2
4 Comments
 
LVL 10

Expert Comment

by:JoeKlimis
Comment Utility
Hi
The easiest way would to be define global variables in the variables file and example of this is

$global:variable1 = " this is variable 1"
$global:variable2 = " this is another one"

in your main script call the variable file like this

.\myvariables.ps1
write-host $variable1

Then at the end of the main script delete the global variables using the following command

 Remove-Variable variable1 -scope global

There are many methods that  can be used , another is create an xml file as that contain the variables.

then import them.

to import the variables  you could use the following.
example xml file is
<?xml version="1.0" encoding="utf-8"?>
<Config>
  <SQL>
    <SOURCE>D:\SQL2008sp2</SOURCE>
    <PCUSOURCE>D:\SQL2008sp2\PCU</PCUSOURCE>
    <CUSOURCE>D:\SQLSPandCu\cu10</CUSOURCE>
    <SQLPort>1433</SQLPort>
    <DriveLetter>D</DriveLetter>
 </SQL>
</Config>

Open in new window


then in your main script add
$ConfigFile = (get-item "myvariablesxml").fullname
[xml] $xmlinput =  get-content $ConfigFile

you can then access the item as follows

$sqlport = $xmlinput.config.sql.sqlport



I hope you find this helpful

Joe
0
 

Author Comment

by:bibi92
Comment Utility
Hello thanks and is it possible to créateur a global.env which contain variables and call it in a script. Thanks bibi
0
 
LVL 10

Accepted Solution

by:
JoeKlimis earned 500 total points
Comment Utility
try the following , run as administrator
[Environment]::SetEnvironmentVariable("JBOSS_HOME","D:\Entwicklung\Programme\jboss-as", "Machine")
[Environment]::SetEnvironmentVariable("M2_HOME",D:\Entwicklung\Programme\apache-maven", "Machine")
[Environment]::SetEnvironmentVariable("TOMCAT_HOME","D:\Entwicklung\Programme\apache-tomcat", "Machine")
[Environment]::SetEnvironmentVariable("ANT_HOME",D:\Entwicklung\Programme\apache-ant", "Machine")


[System.Environment]::SetEnvironmentVariable("PATH", $Env:Path + ";D:\Entwicklung\Programme\mysql\bin;D:\Entwicklung\Programme\apache-maven\bin;D:\Entwicklung\Programme\apacheant\bin;D:\Entwicklung\Programme\eclipse\jre\bin", "Machine")
              

Open in new window

0
 

Author Closing Comment

by:bibi92
Comment Utility
Thanks regards bibi
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Synchronize a new Active Directory domain with an existing Office 365 tenant
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now