web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Powershell/VBScript st...
Power Automate
Answered

Powershell/VBScript stuck ignoring timeout

(1) ShareShare
ReportReport
Posted on by 4
Greetings
 
I am working on a workflow on PowerAutomate (PA) Descktop on a remote Windows 11 server. It loops through entries in a csv and for each entry it runs a Powershell/VBScript (I have tried both) to run the python3.13 interpreter on a python script to extract certain data from a source.
 
The problem is that it sometimes gets stuck indefinitely in that specific action. Even if I set timeout settings in either the VB/Powershell script or in the PA action settings, it sometimes gets ignored and never terminates.
 
This phenomenon occurs at random from what I can tell. It can happen at the 5th entry or the 25th. It does not seem to happen when I set a few breakpoints to test it. It also occurs both when I am connected to the server it runs on and when I am not.
 
What can I do to work around it?
I have the same question (0)
  • Verified answer
    Jon Unzueta Profile Picture
    1,834 Super User 2026 Season 1 on at

    This is a tricky but not uncommon issue when running Power Automate Desktop (PAD) flows that invoke external scripts like Python via PowerShell or VBScript — especially on remote servers.

    Here’s a breakdown of what might be happening and how you can work around it:


    🧠 Why It Gets Stuck Randomly

    1. Zombie Processes: Sometimes the Python process hangs due to:

      • Waiting for input/output (e.g., stdin, stdout)
      • File locks or access issues
      • Network or API timeouts inside the script
    2. PAD Timeout Not Enforced: PAD’s timeout settings on script actions don’t always kill the underlying process, especially if the script spawns a child process (like python.exe).

    3. Remote Desktop Session Effects: If the server is headless or the session is disconnected, some scripts may behave differently (especially if they rely on UI or environment variables).


     Workaround Strategies

    1. Use Start-Process with Timeout Logic in PowerShell

    Instead of calling Python directly, use Start-Process and monitor it:

    $process = Start-Process -FilePath "python.exe" -ArgumentList "script.py" -PassThru

    $process | Wait-Process -Timeout 30

    if (!$process.HasExited) {

        $process.Kill()

        Write-Output "Process killed due to timeout."

    }

    This gives you manual control over the timeout and ensures the process is terminated.


    2. Log and Retry Mechanism

    Wrap the script call in a try/catch block and log failures. You can then:

    • Retry the failed entry
    • Skip and continue the loop

    3. Run Python via .bat File

    Sometimes calling a .bat file that wraps the Python call is more stable:

    @echo off

    python script.py %1

    Then call the .bat from PAD or PowerShell.


    4. Use a Queue-Based Approach

    Instead of looping in PAD, consider:

    • Writing all CSV entries to a queue (e.g., SharePoint list, SQL, or Azure Queue)
    • Triggering a cloud flow or scheduled PAD flow to process one item at a time

    This isolates failures and avoids long-running loops.


    5. Monitor with Task Scheduler or Watchdog Script

    Have a separate watchdog script that:

    • Monitors for long-running python.exe processes
    • Kills them if they exceed a threshold
    🏷️ Tag me if you have any further questions or if the issue persists.
    ✅ Click "Accept as Solution" if my post helped resolve your issue—it helps others facing similar problems.
    ❤️ Give it a Like if you found the approach useful in any way.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 557

#2
Valantis Profile Picture

Valantis 328

#3
David_MA Profile Picture

David_MA 264 Super User 2026 Season 1

Last 30 days Overall leaderboard