Hi,
After doing a lot of research on google ,I myself found the solution.
I used new PowerShell script to execute batch file in PowerShell and to get exitCodes of batch files to PowerShell .My new PowerShell script given below
param(
[String]$FilePath="D:\Scripts\MyBatchFile.bat 'C:\PSInstall' 'D:\TempDelete' 'C:\PSInstall\cert' AdminId AdminPwd 'Prod'" )
function ABC()
{
try{
$Command="$FilePath"
cmd /c $Command |Out-String
exit 0
}
catch{
write-host "-----------------------------------------------------------" -ForegroundColor Green
write-host "Caught an exception:" -ForegroundColor Red
write-host "Exception Type: $($_.Exception.GetType().FullName)" -ForegroundColor Red
write-host "Exception Message: $($_.Exception.Message)" -ForegroundColor Red
write-host "-----------------------------------------------------------" -ForegroundColor Green
exit 1
}
write-host "The Last Exit Code is:" $LastExitCode
}
$ErrorActionPreference = "Stop"
ABC
above script totally solved my problem.
$LastExitCode returns 0 if success and 1 if failure.