Carlos D. Zapata
Carlos D. Zapata

Reputation: 139

Non-blocking Powershell script inside Power Automate flow

I have a very simple Powershell script inside a Power Automate Desktop flow. The script starts a desktop application (just an mstsc command). So far so good. My problem is how to run the script as non-blocking, or maybe how to branch the flow and run another branch in parallel (if this is even possible), so I can continue running further steps of the flow, where I grab objects inside the open application window to execute certain tasks. My flow doesn't run beyond the Powershell script step because the application is still running so the flow stays running that step forever. As soon as I close the application window, the flow execution continues. Any ideas?

Upvotes: 1

Views: 1137

Answers (1)

ZivkoK
ZivkoK

Reputation: 466

Some programs/commands will have to be terminated in order for a Powershell script to continue its execution.

By using the Start-Process cmdlet, you can have more control over this behavior and don't wait for a return code. (You can also run it as a job if launching it in a separate thread if required by using Start-Job, Invoke-Command, etc.)

I will take cmd.exe as an example although there are other ways to deal with this one:

# This portion of code will wait for cmd.exe to be closed in order to continue
Write-Host "launching cmd.exe..."
cmd.exe
Write-Host "cmd.exe is closed, script will continue..."

# This portion of code will NOT wait for cmd.exe to be closed in order to continue
Write-Host "launching cmd.exe..."
Start-Process cmd.exe
Write-Host "cmd.exe is not closed but script continues..."

Upvotes: 2

Related Questions