INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

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

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

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

(OP)
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close