Launching PS in background on a target host

Welcome Forums General PowerShell Q&A Launching PS in background on a target host

This topic contains 2 replies, has 3 voices, and was last updated by

1 year, 3 months ago.

  • Author
  • #83603

    Points: 1
    Rank: Member

    I have a PowerShell script that issues a command like:

    $my_exit = invoke-Command -Session $my_session -ScriptBlock { ... } -Args

    to execute a long script on a target server.
    If the calling script terminates for any reason (maybe, the PC is powered off due to a power failure) the script on the target host terminates as well.
    How can I launch a script on a target host so that it continues even if the calling script closes?
    I made a test adding the -asjob qualifier with no success.

  • #83645

    Points: 101
    Helping Hand
    Rank: Participant

    Try this:

    Run the remote scripts on a remote computer with a persistent session

    $session = New-PSSession -computername "FQDN" -credential Get-Credential
    Invoke-Command -session $session -ScriptBlock {E:\Testing.ps1 "param1"}
  • #83741

    Points: 0
    Rank: Member

    To add to the answer, you could try this:

    $session = New-PSSession -computername "FQDN" -credential Get-Credential
    Invoke-Command -session $session -ScriptBlock {start cmd.exe  "/k powershell.exe ./DoThis.ps1"}

The topic ‘Launching PS in background on a target host’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort