Extending my comment:
# Simple batch file
Get-Content -Path 'D:Tempabc.bat'
echo off
cls
echo Hello
# Run the .bat file
D:Tempabc.bat
# Results - no window is seen unless you are really paying attention since it will flash very fast
<#
Hello
#>
# Using the call operator vs Start-Process
& 'D:Tempabc.bat'
# Results - same window response as above
<#
Hello
#>
Start-Process -FilePath ' D:Tempabc.bat' -Wait
# Results - same window response as above
<#
no results are displayed
#>
Start-Process -FilePath ' D:Tempabc.bat' -PassThru
# Results - same window response as above - But this shows it ran
<#
Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
------- ------ ----- ----- ------ -- -- -----------
19 3 1536 2524 0.00 10160 11 cmd
#>
$A = Start-Process -FilePath ' D:Tempabc.bat'-PassThru;$A.ExitCode
$A
# Results - same window response as above - But this shows it ran
<#
Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
------- ------ ----- ----- ------ -- -- -----------
0 0 0 0.02 19128
#>
If you want to see what the .bat did, then you have to have a pause in the .bat...
echo off
cls
echo Hello
pause
Calling and 3rdP executable from PowerShell, from the TechNet link.
- The Call Operator &
Why: Used to treat a string as a SINGLE command. Useful for dealing
with spaces.
In PowerShell V2.0, if you are running 7z.exe (7-Zip.exe) or another > command that starts with a number, you have to use the command invocation operator &.
The PowerShell V3.0 parser do it now smarter, in this case, you don’t need the & anymore.
Details: Runs a command, script, or script block. The call operator, also known as the "invocation operator," lets you run commands that are stored in variables and represented by strings. Because the call operator does not parse the command, it cannot interpret command parameters
Example(s):
& 'C:Program FilesWindows Media Playerwmplayer.exe' "c:videosmy home video.avi" /fullscreen
Things can get tricky when an external command has a lot of parameters or there are spaces in the arguments or paths!
With spaces, you have to nest Quotation marks and the result is not always clear!
In this case it is better to separate everything like so:
$CMD = 'SuperApp.exe'
$arg1 = 'filename1'
$arg2 = '-someswitch'
$arg3 = 'C:documents and settingsuserdesktopsome other file.txt'
$arg4 = '-yetanotherswitch'
& $CMD $arg1 $arg2 $arg3 $arg4
or same like that:
$AllArgs = @('filename1', '-someswitch', 'C:documents and settingsuserdesktopsome other file.txt', '-yetanotherswitch')
& 'SuperApp.exe' $AllArgs
For Start-Process, as per the same TechNet link.
($p = Start-Process -FilePath 'F:SWDATINSCD_AN_19000101MediSpan.Install.exe' -ArgumentList '/Autostart:DEV_Medispan_Data' -wait -NoNewWindow -PassThru)
$p.HasExited
$p.ExitCode