2014-12-03 2 views
0

나는 이상한 문제가 임의적으로 발생합니다.New-PsSession이 스크립트에서 작동하지 않습니다.

배경 : i 스크립트를 사용하여 서버에 원격 연결하고 Sheduled-Task를 설치하십시오. 로컬 Sheduled - 작업을 실행하는 동안 나는 로컬 스크립트가 완료되면 알려주는 로그 파일을 폴더에서 지속적으로 확인합니다.

이제 이상한 문제가 발생했습니다. 처음에는 수면 루프가 좋은 이유없이 떠났습니다. 그 다음에 세션이 끝나지 않았 음을 확인하기 위해 매주 새로운 Powershell-Session을 만들기 위해 코드를 변경했습니다.

오늘 밤 문제가 다시 발생하고 적어도 루프가 더 이상 종료되지 않았습니다. 그러나 클라이언트는 3 번째 또는 4 번째 시도 후에 새로운 PS-Session을 구축 할 수 없었습니다.

내 행동 강령의 일부입니다. 그것은 10 시간 중 9에서 잘 작동합니다. 로그의

$SecurePassWord = ConvertTo-SecureString -AsPlainText $Password -Force 
    $Cred = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $Username, $SecurePassWord 
    $pssessionoption = new-pssessionoption -operationtimeout 7200000 -IdleTimeout 7200000 

    #i create a Session after that , plant a sheduled task and start waiting here. 

while (!(Invoke-Command -Session $Session -Scriptblock $CheckifClientDone)) 
    { 
    Remove-PSSession -Session $Session 
    Start-Sleep -Seconds 120 
    $doesitconnect = $false 
    $CurrentPatchingState = "1;$Servername;Status=1;$(Get-Date -format 'dd.MM.yyyy hh:mm:ss') Still Waiting" | Out-File -Filepath "C:\Logs\Test_Logs\$Servername.txt" -Append -encoding ASCII 
    while (!($doesitconnect)){ 
    If ($counterfortimeout -eq 300){ #5 Hour timeout 
     $CurrentPatchingState = "2;$Servername;Status=2;$(Get-Date -format 'dd.MM.yyyy hh:mm:ss') Something went Wrong on the Client - Aborting after 5h of waiting" | Out-File -Filepath "C:\Test_Logs\$Servername.txt" -Append -encoding ASCII 
     $CurrentPatchingState = "2;$Servername;Status=2;$(Get-Date -format 'dd.MM.yyyy hh:mm:ss') Something went Wrong on the Client - Aborting after 5h of waiting" | Out-File -Filepath "C:\Logs\Nagios\$Servername.txt" -encoding ASCII 
     exit 
    } 
    $counterfortimeout = $counterfortimeout + 1 
    Try { 
      $Session = New-PSSession -ComputerName $ServerName -credential $Cred -sessionOption $pssessionoption -EA Stop 
      $doesitconnect = $true   
     } 
    Catch [system.exception] 
     { 
      $CurrentPatchingState = "2;$Servername;Status=2;$(Get-Date -format 'dd.MM.yyyy hh:mm:ss') Could not create a Session with the Host at round $counterfortimeout ERROR : $_.Exception.Message" | Out-File -Filepath "C:\Logs\Test_Logs\$Servername.txt" -Append -encoding ASCII 
      $CurrentPatchingState = "2;$Servername;Status=2;$(Get-Date -format 'dd.MM.yyyy hh:mm:ss') Could not create a Session with the Host at round $counterfortimeout ERROR : $_.Exception.Message" | Out-File -Filepath "C:\Logs\Nagios\$Servername.txt" -encoding ASCII 
      Remove-PSSession -Session $Session 
      $doesitconnect = $false 
      Start-Sleep -Seconds 60 
     } 
    } 
    } 

을 Heres 부 : 그것은 그래서 그는 defenetly 3 회 (1 회 루프 2 전에 세션을 만들 수 있었다

1;Server1;Status=1;03.12.2014 03:03:22 Still Waiting 
1;Server1;Status=1;03.12.2014 03:05:23 Still Waiting 
2;Server1;Status=2;03.12.2014 03:05:23 Could not create a Session with the Host at round 2 ERROR Illegal operation attempted on a registry key that has been marked for deletion. For more information, see the about_Remote_Troubleshooting Help topic..Exception.Message 
2;Server1;Status=2;03.12.2014 03:06:23 Could not create a Session with the Host at round 3 ERROR Illegal operation attempted on a registry key that has been marked for deletion. For more information, see the about_Remote_Troubleshooting Help topic..Exception.Message 
2;Server1;Status=2;03.12.2014 03:07:23 Could not create a Session with the Host at round 4 ERROR Illegal operation attempted on a registry key that has been marked for deletion. For more information, see the about_Remote_Troubleshooting Help topic..Exception.Message 
2;Server1;Status=2;03.12.2014 03:08:23 Could not create a Session with the Host at round 5 ERROR Illegal operation attempted on a registry key that has been marked for deletion. For more information, see the about_Remote_Troubleshooting Help topic..Exception.Message 
2;Server1;Status=2;03.12.2014 03:09:23 Could not create a Session with the Host at round 6 ERROR Illegal operation attempted on a registry key that has been marked for deletion. For more information, see the about_Remote_Troubleshooting Help topic..Exception.Message 
. 
. 
. 
2;Server1;Status=2;03.12.2014 08:03:24 Could not create a Session with the Host at round 300 ERROR Illegal operation attempted on a registry key that has been marked for deletion. For more information, see the about_Remote_Troubleshooting Help topic..Exception.Message 
2;Server1;Status=2;03.12.2014 08:04:24 Something went Wrong on the Client - Aborting after 5h of waiting 

3시 1분 22초에서 루프를 체결 회 중일 때) 아이디어에서 벗어났습니다. $ Cred 객체 또는 $ SecurePassWord 객체에 대한 시간 초과가 있습니까? 해당 시간 동안 서버에 접근 할 수 없었습니다. 나는이 아침에 새로운 세션을 만들려고 노력했다.

UPDATE :

Illegal operation attempted on a registry key that has been marked for deletion. For more information, see the about_Remote_Troubleshooting Help topic..Exception.Message 

누구 아이디어를 가지고 : 내가 오류 메시지 캡처 ojk에서 팁 덕분에? 그것은 오늘 밤 4 시간 동안 여러 시간 동안 일어난다. 나는 내 머리를 감쌀 수 없다.

재미있는 측면. 새 Powershell 창을 여는 경우 (실행중인 스크립트가 여전히 연결할 수 없지만). 새로운 PS 창은 연결을 열 수 있습니다. 대상 측의 재부팅으로 문제가 해결되지 않습니다. 그래서 그것의 서버 사이드에 대한 문제를 방어하십시오.

편집 : powershell 프로세스의 전체 procmon 루프를 업로드했습니다. 결과가 너무 길어서 여기에 완전히 게시 할 수 없습니다. http://textuploader.com/oer3

+0

시도를 찾는 문제 .... 해결해야한다는 것 어떤 것. (catch 블록에서 $ _. Exception.Message를 사용하여 얻을 수 있습니다.) – ojk

+0

팁 주셔서 감사합니다. 스크립트에 추가했습니다. 안타깝게도 10 회 중 9 회 작동하고 Microsoft에서만 패치를 한 달에 한 번만 릴리스하므로 실제로 오류를 재현 할 수 없습니다. 나는 그것이 다시 일어나 자마자 게시물을 업데이트 할 것이다. 문제가 될 수있는 다른 일반적인 아이디어? – Ceuse

+0

세션이 시간 초과 될 수 있습니까? pssessionoption의 idletimeout을 -1로 설정하여 유휴 시간 제한을 완전히 비활성화해야합니다. 이 작업을 수행하면 WSMan 셸 시간 초과 값을 사용하게됩니다. – ojk

답변

0

문제는 SCript 자체에는 없지만 사용자 로깅에 대한 Windows 설정에있는 것으로 보입니다.

http://support.microsoft.com/kb/2287297을 사용하고 DisableForceUnload 레지스트리 키를 추가 했으므로 스크립트를 시작한 후에 로깅을하기 전에 문제를 복제 할 수 없습니다.

문제가 다시 발생할 때까지 해결 됨으로 표시됩니다.

는 사용자와 만 NTAUTHORITY의 \ 시스템하지이 스크립트를 시작하는 당신에게 말할 수도있다이 너무 고통 스럽다이었다뿐만 아니라 예외 메시지 자체를 기록하는

+0

참조한 문서를 보면 다음과 같은 내용을 볼 수 있습니다.이 정책은이 Windows 동작으로 인해 응용 프로그램 호환성 문제가 발생할 수있는 경우에만 사용해야합니다. 사용자가 로밍 사용자 프로필의 업데이트 된 버전을 가져올 수 없으므로이 정책을 기본적으로 사용하는 것은 좋지 않습니다. 사람들이 새로운 코드를 배포하기 위해서만 연결하는 서버에서이 기능을 활성화해야합니다. 이것이 사용자에게 문제를 일으킬 수 있다면 어떨까요? – demonicdaron

관련 문제