2012-06-01 87 views
0

试图为我们的SMTP群集编写监视脚本(Powershell),该群集有时有3个节点正在写入。使用Get-NlbClusterNode远程尝试时访问被拒绝

当我在本地,在SMTP集群运行以下命令:

Get-NlbClusterNode 

我得到的输出,我需要。

但是,如果我试图从远程服务器(相同的网络和域)同我得到一个:

[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

您必须使用作为所有主机上的管理员组成员的登录名连接到群集。 –

+0

嗨大卫,非常感谢你的回复。我作为域管理员(每个节点上的本地管理员组的成员)进行连接。当我登录本地时,远程使用相同的帐户,它在本地工作。任何其他想法?最好的祝福 – user1281991

回答

0

我有同样的问题。

花了我一阵子弄清楚。我从我的服务中运行Powershell。该服务在所有主机上以相同的用户帐户运行,但密码是在每个主机/集群节点上随机生成的,这就是为什么我得到“拒绝访问...”的原因。一旦将密码更改为相同,一切正常。

0

我找到了一些解决方法。 模拟拥有管理credentional在远程会话

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

而且禁用UAC并重新启动机器。

相关问题