View Single Post
Old 08-15-2008   #2 (permalink)
Kryten


 
 

Re: Include another script, keep variables in included script?

This is just one possible way:-
(Both scripts are in my 'D:\Posh' directory.

tmp.ps1
-----------
$Test = "Here"
$There = "There"
---------------------

tmp2.ps1
------------
&D:\Posh\tmp.ps1
" These variables and values are from tmp:"
Write-Host "$Test & $There"
----------------------------

Nowwith your current directory set as D:\Posh do
Quote:

>.\tmp2.ps1
You should get:-
These variables and values are from tmp:
Here & There

Essentially just using the 'Call' Operator '&' to include the tmp.ps1

Hope this helps,
Stuart


My System SpecsSystem Spec