Score:0

Start remote PowerShell command and have it finish even if disconnected

gb flag

If I start a remote PowerShell session with:

Enter-PSSession -ComputerName somecomputer

Then I want to execute a long-running process:

[somecomputer]: PS C:\> C:\SomeApp\DoSomething.exe

If my remote session is disconnected for whatever reason - such as a local machine network outage or reboot - is there any way to ensure that the command still completes on the server?

From what I'm seeing, it seems to go away as soon as my PS session dies. I've also tried Start-Process, but it seems to behave the same.

I'm trying to run things on a server without having to RDP in. Still a beginner in PowerShell, so I'm sure there are plenty of things I'm missing. I'm on Win10, PowerShell 7, connecting to Windows Server 2016, but I assume it would be the same anywhere.

br flag
take a look at `Get-Help about_remote*` for some ideas. [*grin*]
Score:0
gb flag

Looks like I don't need a new session at all, just the correct syntax:

Invoke-Command `
-ComputerName somecomputer `
-AsJob `
-ScriptBlock {& 'C:\SomeApp\DoSomething.exe'}

The -AsJob parameter runs the command as a background service. The -ScriptBlock parameter lets me run an exe.

Score:0
es flag

I think what you're looking for is New-PSsesion

Enter-PSSession: Starts a temporary interactive session with a remote computer. You can have only one interactive session at a time using Enter-PSSession. Exiting the session destroys it.
New-PSSession: Creates a PERSISTENT connection to a local or remote computer. Exiting the session does not destroy it, it is still available to connect to again unless you do something like Disconnect-PSSession or it times out.
Furthermore, with New-PSSession you can assign the session a Name or to a variable for easier re-use, etc.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.