Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing variable between scripts issue - not working in batch file - Help

Status
Not open for further replies.

psnovice

Programmer
Jan 22, 2013
3
US
Hi,

This is working from running PS1 but not working when running PS1 from batch file:


sprint2.ps1:
-----------


Set-StrictMode -Version Latest

$var1main=""
$var1=""


if ($var1main -eq $var1) {.\script1.ps1}
$var1main=$var1
Write-Host ("Value 1 main: " + $var1main)



sprint1.ps1:

-----------
Set-StrictMode -Version Latest

$global:var1=0
$global:var11=0

if ($var11 -eq 0)
{
$var1=3
}
else
{
$var1=4
}
Write-Host ("Value 1: " + $var1)
$global:var1=$var1

Result of script2.ps1:
---------------------
Value 1 main: 3



test1.bat:
----------
powershell.exe " &""<Scriptpath>\script2.ps1"""


Result of test1.bat: Value 1 main: null



When running script2.ps1 from test1.bat batch file, "Value 1 main" is null but when running script2.ps1, the "Value 1 main" is 3.

Please help. what could be the issue.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top