# Start executable and stop script from running

**URL:** <https://forums.powershell.org/t/start-executable-and-stop-script-from-running/10144>\
**Category:** PowerShell Help\
**Created:** [February 16, 2018, 7:35am UTC](https://forums.powershell.org/t/start-executable-and-stop-script-from-running/10144 "2018-02-16T07:35:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![windows-liveuser86](https://avatars.discourse-cdn.com/v4/letter/w/e5b9ba/32.png) [@windows-liveuser86](https://forums.powershell.org/u/windows-liveuser86)\
**Post date:** [February 16, 2018, 7:35am UTC](https://forums.powershell.org/t/start-executable-and-stop-script-from-running/10144/1 "2018-02-16T07:35:26Z")

</div>

I use this code to start an executable on multiple computers.

```
Invoke-Command -ComputerName Comp1, Comp2, Comp3 -ScriptBlock {
D:\XXXXX.exe }
```

The script keeps running until the executable is stopped on all machines.  
Is there a way to exit the script without terminating the executable?

---

<div class="post-metadata">

**Author:** ![sanchez](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@sanchez](https://forums.powershell.org/u/sanchez)\
**Post date:** [February 16, 2018, 7:41am UTC](https://forums.powershell.org/t/start-executable-and-stop-script-from-running/10144/2 "2018-02-16T07:41:24Z")

</div>

You could look into using jobs [https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Core/Invoke-Command?view=powershell-5.1](https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Core/Invoke-Command?view=powershell-5.1)

> **[Geek School: Learn How to Use Jobs in PowerShell](https://www.howtogeek.com/138856/geek-school-learn-how-to-use-jobs-in-powershell/)**
>
> PowerShell has four types of jobs – Background Jobs, Remote Jobs,WMI Jobs and Scheduled Jobs. Join us as we find out what they are and how we can use them.

From the examples:

$s = New-PSSession -ComputerName Server01, Server02  
Invoke-Command -Session $s -ScriptBlock {Get-EventLog system} -AsJob

Id Name State HasMoreData Location Command

* * *

1 Job1 Running True Server01,Server02 Get-EventLog system

$j = Get-Job

$j | Format-List -Property \*

HasMoreData : True  
StatusMessage :  
Location : Server01,Server02  
Command : Get-EventLog system  
JobStateInfo : Running  
Finished : System.Threading.ManualResetEvent  
InstanceId : e124bb59-8cb2-498b-a0d2-2e07d4e030ca  
Id : 1  
Name : Job1  
ChildJobs : {Job2, Job3}  
Output : {}  
Error : {}  
Progress : {}  
Verbose : {}  
Debug : {}  
Warning : {}  
StateChanged :

$results = $j | Receive-Job

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:36pm UTC](https://forums.powershell.org/t/start-executable-and-stop-script-from-running/10144/3 "2024-05-16T20:36:22Z")

</div>


