Start executable and stop script from running

Welcome Forums General PowerShell Q&A Start executable and stop script from running

This topic contains 1 reply, has 2 voices, and was last updated by

Jon
 
Participant
9 months ago.

  • Author
    Posts
  • #93814

    Participant
    Points: 1
    Rank: Member

    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?

  • #93816
    Jon

    Participant
    Points: 26
    Rank: Member

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

    https://www.howtogeek.com/138856/geek-school-learn-how-to-use-jobs-in-powershell/

    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

The topic ‘Start executable and stop script from running’ is closed to new replies.