Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2012-03-14
4
Medium Priority
?
287 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 2000 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

660 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