2012-06-01 89 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並重新啓動機器。

相關問題