0

Windows PowerShell을 사용하여 설치 프로세스 중에 사용자의 Windows 자격 증명을 쿼리하고 유효성을 검사합니다. 그것은 어제까지 잘 작동했습니다. 이제 우리 회사의 IT 부서에서 도메인 컨트롤러의 일부 구성을 변경했으며 다음 예외가 발생합니다."ValidateCredentials"의 예외 "서버에서 디렉터리 요청을 처리 할 수 ​​없습니다."

 
Exception calling "ValidateCredentials" with "2" argument(s): "The server cannot 
handle directory requests." 
At line:32 char:5 
+ if ($pc.ValidateCredentials($username, $credential.GetNetworkCredenti ... 
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : NotSpecified: (:) [], MethodInvocationException 
    + FullyQualifiedErrorId : DirectoryOperationException 

나는 이미 SSL 연결이 누락 된 것으로 밝혀졌습니다. 나는 어딘가에 코드에 ContextOptions.SecureSocketLayer을 추가해야한다. 질문 :이 매개 변수를 올릴 적절한 위치는 어디입니까? PowerShell에 대한 예제를 찾을 수 없습니다.

$DefaultNC = "DC=$($system.Domain -replace '\.',',DC=')" 
# ... 
$pc = New-Object -TypeName System.DirectoryServices.AccountManagement.PrincipalContext 'Domain', $system.Domain, $DefaultNC, ([System.DirectoryServices.AccountManagement.ContextOptions]'SecureSocketLayer,Negotiate') 

인증 옵션 (Negotiate 또는 SimpleBind) :

$credential = $Host.UI.PromptForCredential("Need credentials.", "For using Windows Integrated Authentication please provide the login information for the user that has access to the Microsoft SQL Server database.", "", "") 
if (!$credential) { 
    Write-Output "No credentials provided" 
    return 
} 

[System.Reflection.Assembly]::LoadWithPartialName('System.DirectoryServices.AccountManagement') 

$system = Get-WmiObject -Class Win32_ComputerSystem 

if ($credential.GetNetworkCredential().Domain) { 
    Write-Output "Credentials contain domain" 
    if ($credential.GetNetworkCredential().Domain -eq $system.Name) { 
     Write-Output "Domain is local system" 
     $pc = New-Object -TypeName System.DirectoryServices.AccountManagement.PrincipalContext 'Machine', $system.Name 
    } else { 
     Write-Output "Domain is network domain" 
     $pc = New-Object -TypeName System.DirectoryServices.AccountManagement.PrincipalContext 'Domain', $credential.GetNetworkCredential().Domain 
    } 
    $username = $credential.UserName 
} elseif (0, 2 -contains $system.DomainRole) { 
    $pc = New-Object -TypeName System.DirectoryServices.AccountManagement.PrincipalContext 'Machine', $system.Name 
    $username = $system.Name + '\' + $credential.GetNetworkCredential().UserName 
} else { 
    $pc = New-Object -TypeName System.DirectoryServices.AccountManagement.PrincipalContext 'Domain', $system.Domain 
    $username = $system.Domain + '\' + $credential.GetNetworkCredential().UserName 
} 

if ($pc.ValidateCredentials($username, $credential.GetNetworkCredential().Password)) { 
    Write-Output "Validation successfull" 
} else { 
    Write-Output "Validation failed" 
} 
+3

을 'prin'에 추가 할 수 있습니다. cipalcontext' 것 같습니다 .... https : //msdn.microsoft.com/en-us/library/bb339842 (v = vs.110) .aspx – Kiran

답변

1

mentioned by Kiran in the comments, 당신은 PrincipalContext 생성자에 ContextOptions 값을 전달할 수 있습니다

여기에 내가 자격 증명을 확인하는 데 사용되는 스크립트입니다 를 지정해야하므로 'SecureSocketLayer,Negotiate'

+0

답변 해 주셔서 감사합니다. 구문이 정확합니다. 하지만 $ pc.ValidateCredentials를 호출하면 여전히 DirectoryOperationException이 발생합니다. 그래서 누락 된 SecureSocketLayer는 내 문제의 원인이 아닌 것 같습니다. 나는 무엇이 바뀌 었는지 전혀 모른다. – Andre