I want to call a simple Powershell script file that should return either 0 or 1 upon the ps script failure or pass respectively, from a batch file . And based upon the return value, I want to continue further or quit.
The following illustrates what I have tried out:
startup.bat:-
@ECHO OFF
SET x = powershell C:\Users\saravind\Desktop\pingping.ps1
if "%x%" == 1 then (
doSomething1
ECHO Ran project 1
)
pingping.ps1:-
$someIP = '192.168.173.299'
$result = $true
try { Test-Connection $someIP -Source localhost -ErrorAction Stop }
catch { $result = $false }
What I'm trying to achieve is that on the execution of pingping.ps1 if it can successfully ping the '192.168.173.299', it should return some value, say 1 to the batch file from which it was being called. And if the ping fails, it should return 0 so that the batch file will not proceed with 'doSomething' Eventhough the pingping fails, it proceeds with doSomething with my code. What's wrong with my code.
Thanks in advance.