원격 PowerShell 명령을 시작하고 연결이 끊어진 경우에도 완료되도록 합니다.

원격 PowerShell 명령을 시작하고 연결이 끊어진 경우에도 완료되도록 합니다.

다음을 사용하여 원격 PowerShell 세션을 시작하는 경우:

Enter-PSSession -ComputerName somecomputer

그런 다음 장기 실행 프로세스를 실행하고 싶습니다.

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

로컬 컴퓨터 네트워크 중단 또는 재부팅과 같은 어떤 이유로든 원격 세션의 연결이 끊어진 경우 명령이 서버에서 계속 완료되도록 할 수 있는 방법이 있습니까?

제가 볼 때 PS 세션이 종료되자마자 사라지는 것 같습니다. 나도 시도해 보았지만 Start-Process동일한 동작을 하는 것 같습니다.

RDP를 사용하지 않고 서버에서 작업을 실행하려고 합니다. 아직 PowerShell의 초보자이므로 부족한 점이 많을 것이라고 확신합니다. 저는 Win10, PowerShell 7을 사용하여 Windows Server 2016에 연결하고 있지만 어디에서나 동일할 것이라고 가정합니다.

답변1

내 생각에 당신이 찾고 있는 것은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.

답변2

새 세션이 전혀 필요하지 않은 것 같습니다. 올바른 구문만 있으면 됩니다.

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

매개 -AsJob변수는 명령을 백그라운드 서비스로 실행합니다. 매개 -ScriptBlock변수를 사용하면 exe를 실행할 수 있습니다.

관련 정보