2012-06-01 5 views
0

SMTP 클러스터에 대한 모니터링 스크립트 (Powershell)를 쓰려고합니다.이 클러스터에는 3 개의 노드가 있습니다. 내가 필요로하는 출력을 얻을Get-NlbClusterNode를 사용하여 원격으로 액세스 할 때 액세스가 거부되었습니다.

Get-NlbClusterNode 

: 나는 로컬로 SMTP 클러스터에서이 명령을 실행

.

하지만 원격 서버 (동일한 네트워크 및 도메인)에서 동일한하려고하면 나는 얻을 : 왜 그

[smtp-s001a]: PS C:\> Get-NlbClusterNode 
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) 
+ CategoryInfo   : 
+ FullyQualifiedErrorId : 
AccessDenied,Microsoft.NetworkLoadBalancingClusters.PowerShell.GetNlbClusterNode 

입니까? 나에게 액세스 권한을 부여하는 "Get-NlbClusterNODE"명령 만 거부됩니다. 예를 들어 "Get-NlbCluster"는 정상적으로 작동합니다.

어떤 조언이 필요합니까?

+0

모든 호스트에서 Administrators 그룹의 구성원 인 로그온 이름을 사용하여 클러스터에 연결해야합니다. –

+0

안녕하세요, David. 답장을 보내 주셔서 대단히 감사합니다. 도메인 관리자 (모든 노드에서 로컬 관리자 그룹의 구성원)로 연결 중입니다. 로컬로 로그온 할 때 원격으로 사용되는 동일한 계정. 로컬로 작동합니다. 다른 생각? 친애하는 – user1281991

답변

0

나는 동일한 문제가있었습니다.

알아 내고 싶습니다. Powershell을 서비스로 사용하고있었습니다. 서비스는 모든 호스트에서 동일한 사용자 계정으로 실행되지만 각 호스트/클러스터 노드에서 무작위로 암호가 생성되므로 "액세스가 거부되었습니다"라는 오류가 발생합니다. 암호를 동일하게 변경하면 모든 것이 정상적으로 작동합니다.

0

몇 가지 해결 방법을 발견했습니다.

function EntryPoint() 
{ 
    ImportModule-Impersonate; 

    $impersonate = new-object UserSession.Impersonate; 
    try 
    { 
     if ($impersonate.Login("SKODA", "Administrator", "*****") -eq $false) { 
      throw new Exception("Invalid credentials"); 
     } 
     Import-Module NetworkLoadBalancingClusters 
     Get-NlbClusterNode;  
    } 
    finally 
    { 
     $impersonate.Dispose(); 
    } 
}; 

function ImportModule-Impersonate { 

$assem = @(); 

$source = @" 
using System; 
using System.Collections.Generic; 
using System.Runtime.InteropServices; 
using System.Security.Principal; 
using System.Text; 

namespace UserSession 
{ 
    public class Impersonate : IDisposable 
    { 
     public const int LOGON32_LOGON_INTERACTIVE = 2; 
     public const int LOGON32_PROVIDER_DEFAULT = 0; 

     private WindowsImpersonationContext _impersonationContext; 

     [DllImport("advapi32.dll")] 
     public static extern int LogonUserA(String lpszUserName, 
              String lpszDomain, 
              String lpszPassword, 
              int dwLogonType, 
              int dwLogonProvider, 
              ref IntPtr phToken); 

     [DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)] 
     public static extern int DuplicateToken(IntPtr hToken, 
               int impersonationLevel, 
               ref IntPtr hNewToken); 

     [DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)] 
     public static extern bool RevertToSelf(); 

     [DllImport("kernel32.dll", CharSet = CharSet.Auto)] 
     public static extern bool CloseHandle(IntPtr handle); 

     public bool Login(String domain, String userName, String password) 
     { 
      IntPtr token = IntPtr.Zero; 
      IntPtr tokenDuplicate = IntPtr.Zero; 

      if (RevertToSelf()) 
      { 
       if (LogonUserA(userName, domain, password, LOGON32_LOGON_INTERACTIVE, 
           LOGON32_PROVIDER_DEFAULT, ref token) != 0) 
       { 
        if (DuplicateToken(token, 2, ref tokenDuplicate) != 0) 
        { 
         WindowsIdentity tempWindowsIdentity = new WindowsIdentity(tokenDuplicate); 
         _impersonationContext = tempWindowsIdentity.Impersonate(); 

         if (_impersonationContext != null) 
         { 
          CloseHandle(token); 
          CloseHandle(tokenDuplicate); 
          return true; 
         } 
        } 
       } 
      } 
      if (token != IntPtr.Zero) 
      { 
       CloseHandle(token); 
      } 
      if (tokenDuplicate != IntPtr.Zero) 
      { 
       CloseHandle(tokenDuplicate); 
      } 
      return false; 
     } 

     public void Logout() 
     { 
      if (_impersonationContext != null) 
      { 
       _impersonationContext.Undo(); 
       _impersonationContext = null; 
      } 
     } 

     public void Dispose() 
     { 
      Logout(); 
     } 
    } 
} 
"@; 

    Add-Type -ReferencedAssemblies $assem -TypeDefinition $source -Language CSharp 
} 

EntryPoint; 
0

원격 세션에서 관리 credentional와 로 가장 또한 UAC 및 시스템 재부팅을 사용하지 않도록 설정합니다.

관련 문제