
아래 Powershell 코드는 원격을 시작하는 방법입니다 PSSession
.
$compName = "server1"
$jobname = "admin_test"
$cred = Get-Credential -UserName "DOMAIN\$env:username" -Message "DOMAIN\$env:username password"
$s_opt = New-PSSessionOption -IdleTimeout -1
$s1 = New-PSSession -ComputerName $compName -Name $jobname -SessionOption $s_opt -Credential $cred
이것은 대부분의 경우 훌륭하게 작동하며 $s1 | Enter-PSSession
명령을 실행하거나 Invoke-Command -Session $s1 -ScriptBlock {some code}
. 완료하는 데 많은 시간이 걸릴 수 있는 특정 작업(일반적으로 Python 또는 Java)을 실행할 때 PSSession이 예기치 않게 종료되는 경우가 있습니다.
다른 또는 더 많은 을 추가해야 합니까 -SessionOption
?
PSSession이 종료된 이유를 알아낼 수 있는 방법이 있습니까?
편집하다
아래는New-PSSessionOption
PS C:\> New-PSSessionOption
MaximumConnectionRedirectionCount : 5
NoCompression : False
NoMachineProfile : False
ProxyAccessType : None
ProxyAuthentication : Negotiate
ProxyCredential :
SkipCACheck : False
SkipCNCheck : False
SkipRevocationCheck : False
OperationTimeout : 00:03:00
NoEncryption : False
UseUTF16 : False
IncludePortInSPN : False
OutputBufferingMode : None
MaxConnectionRetryCount : 0
Culture :
UICulture :
MaximumReceivedDataSizePerCommand :
MaximumReceivedObjectSize :
ApplicationArguments :
OpenTimeout : 00:03:00
CancelTimeout : 00:01:00
IdleTimeout : -00:00:00.0010000
편집 2
을 시작하기 위해 루틴에 아래 코드를 추가했지만 약 2시간 후에도 아무 이유 없이 계속 중지됩니다 PSSession
.PSSession
## -IdleTimeoutSec in sec/min * min/hr * hrs/day * days
Disconnect-PSSession -Session $s1 -IdleTimeoutSec 60*60*24*3
-IdleTimeoutSec
이는 Microsoft Powershell 문서의 선택적 매개변수 에 대한 다음 설명을 기반으로 했습니다.연결 끊기-PSSession
Powershell 명령에 대한 MS 문서 예제 3의 9번째 명령에도 잘 설명되어 있습니다.Connect-PSSession
예아래에서 발췌했습니다.
# The ninth command disconnects from the session in the $s variable.The administrator closes PowerShell and closes the computer. She can reconnect to the session on the next day and check the script status from her work computer.
PS C:\> Disconnect-PSSession -Session $s -OutputBufferingMode Drop -IdleTimeoutSec 60*60*15
MS 문서의 오류이거나 다른 Powershell 버전과 관련된 한 가지 이상한 점은 위 명령이 다음 오류를 제공한다는 것입니다.
Disconnect-PSSession : Cannot bind parameter 'IdleTimeoutSec'. Cannot convert value "60*60*24*3" to
type "System.Int32". Error: "Input string was not in a correct format."
At line:1 char:76
+ ... sion -Session $x -IdleTimeoutSec 60*60*24*3
+ ~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Disconnect-PSSession], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.Disconnect
PSSessionCommand
그러나 다음 명령은 전달된 정수 값이 -IdleTimeoutSec
문자열로 변환될 때 제대로 작동합니다.
PS C:> Disconnect-PSSession -Session $s1 -IdleTimeoutSec "259200"
Id Name ComputerName ComputerType State ConfigurationName Availability
-- ---- ------------ ------------ ----- ----------------- ------------
5 admin_test Server1 RemoteMachine Disconnected Microsoft.PowerShell None
답변1
IdleTimeout
사용한 것 보다 다른 기본 시간 초과 매개변수가 실행 중일 수 있습니다 .
매개변수 없이 명령을 실행합니다 New-PSSessionOption
. 확인을 원하시면 게시물에 출력을 포함하세요. 에 특별한 주의를 기울이십시오 OperationTimeout
.
에 대한 문서에서 새로운 PSSessionOption:
-작업 시간 초과
세션의 모든 작업이 실행될 수 있는 최대 시간을 결정합니다. 간격이 만료되면 작업이 실패합니다. 값을 밀리초 단위로 입력하세요.
기본값은 180000(3분)입니다. 값 0(영)은 시간 초과가 없음을 의미합니다. 작업은 무기한으로 계속됩니다.