Solved

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

Posted on 2012-03-14
4
282 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
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 10

Accepted Solution

by:
JoeKlimis 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

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…
This article will help you understand what HashTables are and how to use them in PowerShell.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

770 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