I am attempting to run a executable with arguments from a remote computer in PowerShell, and while I have gotten the PowerShell command to work, it is not properly handling errors that the executable throws.
So the below script executes as expected as long as the file $filename points to exists, but the script will also appear to execute successfully if the file does not, which leads to problems in the scheduler I am trying to tie this into. My expectation would be that PowerShell throws an error such as "File not found", but that is not happening. So is there anything I can add to this script to make that behavior happen?
$ErrorActionPreference = "stop"
$rSession = New-PSSession -ComputerName ServerName
$fileName = c:\file.txt
Invoke-Command -ScriptBlock {Start-Process -FilePath "D:\CAMRA\PFX\PFLNS.EXE" -ArgumentList " /SD:\CAMRA\CAMINI\Z_PRODNP_SQL_TEST.INI GLSWEEP 50 {DN}~$fileName~{T}" -Wait} -Session $rSession
Remove-PSSession $rSession
It is also possible that I am not calling the .exe correctly through PowerShell to do what I am looking to, so I would be open to any suggestions on how I cam modify this script.
Thanks, Phil