Solved

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

Posted on 2012-03-14
4
286 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 11

Expert Comment

by:Joe Klimis
ID: 37720037
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
ID: 37721894
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 11

Accepted Solution

by:
Joe Klimis earned 500 total points
ID: 37722945
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
ID: 37766474
Thanks regards bibi
0

Featured Post

IoT Devices - Fast, Cheap or Secure…Pick Two

The IoT market is growing at a rapid pace and manufacturers are under pressure to quickly provide new products. Can you be sure that your devices do what they're supposed to do, while still being secure?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

632 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