Powershell Crash after couple of hours

I'm experiencing with weird case with my Powershell script. I have written a script that's execute an .exe file this exe runtime is about 3 hours but constantly crashing after 2 hors (1-2 minutes more or less)

I have break my head try to figure out why the process crashing eventually I found that the .exe crashing because the powershell crashing.

Here is the process execution command:

$Proc = Start-Process -FilePath $ExePath -ArgumentList $Arguments -NoNewWindow -PassThru
$Proc | Wait-Process -Timeout 28800 -ea 0 -ev timeouted

After I realized this issue cased by the Powershell I have enabled windows powershell logging and find an error message "the pipeline has been stopped"

The script need perform more actions after the process ends and get its exit code, that's why I used the -PassThru flag. I have tried to run it without using the PassThru flag or the Process-Wait command, the result stayed the same (the process crashed after 2 hours but there wasn't log with the message "The pipeline has been stopped")

Important points:

  1. the .exe file is soured with try;catch blocks with logger but did not logged any thing when crashing- this is not a runtime error in the .exe file
  2. When running the .exe independently from the command line its finish successfully after ~3 hours
  3. The Powershell script run with Administrator privileges
  4. The exe is not casing the crashing due to high CPU/Memory/Disk usage

I will follow up once I will have more updates.

Thanks for all the helpers. Your help is much appreciated!

In my opinion the Start-Process cmdlet is good for quick things. But, it leaves a lot to be desired when trying to debug why an exe isn't behaving.

To work around this in your case it might be useful to use .Net objects to redirect and change certain things about your instantiation. I put an example function below that I've used when having trouble debugging exe runs.

function Start-Exe
{
    param
    ( [string]$exePath, [string]$args1 )

    $returnVal = $false
    $pinfo = New-Object System.Diagnostics.ProcessStartInfo
    $pinfo.FileName = $exePath
    $pinfo.RedirectStandardError = $true
    $pinfo.RedirectStandardOutput = $true
    $pinfo.UseShellExecute = $false
    $pinfo.Arguments = $args1
    $p = New-Object System.Diagnostics.Process
    $p.StartInfo = $pinfo
    $p.Start() | Out-Null
    $p.WaitForExit()
    $stdout = $p.StandardOutput.ReadToEnd()
    $stderr = $p.StandardError.ReadToEnd()
    $exitCode = $p.ExitCode
    #OutputFile can be some log file, or just use write-host to pump to console
    #$stdout | Add-Content $global:OutputFile
    #$stderr | Add-Content $global:OutputFile

    return $exitCode
}

windows - Powershell Crash after couple of hours, I have written a script that's execute an .exe file this exe runtime is about 3 hours but constantly crashing after 2 hors (1-2 minutes more or less). I have break my  Performance Slows Down Substantially Couple of Hours after Reboot Each time I reboot my system a cycle of good performance for a couple of hours and then degradation into an extremely slow performance, sluggish/stalling software begins.

You can try it without using Wait-Process and see if it is reproducible.

Start-Process with -Wait parameter .

or Create it in a Job without -Wait and wait for the Job using Wait-.Job cmdlet

Powershell Crash after couple of hours - windows - iOS, I have written a script that's execute an .exe file this exe runtime is about 3 hours but constantly crashing after 2 hors (1-2 minutes more or less) I have break my  PowerShell Crash Course Don Jones 10. Week 1, Day 5: Configuration Baselines This is the last tip for your first week of PowerShell, and it’s a doozy. First up is a pair of cmdlets that read and write XML‐formatted files: Import­CliXML and Export­CliXML.

I had the same symptom when trying to execute an 8 hour process, it would always die after 2 hours, you need to clear the powershell IdleTimeout.

This answer helped me

PowerShell ISE Freezes after executing WinForms, Thoughts on why my ISE constantly crashes when working on winform all scripts were reloaded and afterwards it worked for some hours again. 3000 lines with dozens of winform objects, are crashing every few minutes;  Windows 10 hard crashes about every 2 hours. Everything just freezes, no blue screen.

18204: PowerShell & PowerShel (Admin) crash after a, 18204: PowerShell & PowerShel (Admin) crash after a few seconds. Anyone else experincing this? if so, please upvote this feedback. TIA. Smll computer gtz rkt. ️ FINALLY SOLVED: Windows 10 Start Button Not Working, Cortana, Edge and Store Not Working - Duration: 10:25. Windows 10 Guru 1,839,189 views

PowerShell crashes when using start-job in a loop – The Full Circle, [Update from a few hours later] After further investigation it wasn't the code below, making the change just prevented the error from appearing for  Learn Windows PowerShell Fast Crash Course - select the contributor at the end of the page - For most Windows administrators, the world of system admin revolves around a collection of graphical system management tools, most with names ending in manager.

Terminal shows an empty window and then crashes · Issue #1364 , After some difficulties and a few attempts I was able to build and deploy the project Windows Terminal crashes with Powershell 7 #1399. Iam newbie in powershell command, just want to ask what are the command to filter the event viewer eventlogs lets say for last 2 hours, 7 days etc.. I tried this command {($_.TimeWritten).Date -eq (Get-Date).date which only give the latest eventlog.

Comments
  • Which version of PowerShell ?
  • Hi , I'm using 4.0
  • Hi David, thanks for your reply. I know that there is noting wrong with the exe execution. the powershell process is crashing (when I run the exe independently everything running smooth and its exit code 0) I'm trying to figure out why the powershell stop after two hours (constantly) thanks , shlomy.
  • Hi , I have already tried it , it look like the exe process is registered in something like the CPU under the Powershell process although the PS process finished.