2017-02-14 58 views
0

我有2個服務器(Windows Server 2012 R2)在同一個域中。 我Server01上執行命令:調用命令不需要憑據

Invoke-Command -ComputerName server02 -Credential Administrator -ScriptBlock {Get-Culture} 

我給我的管理員(Server2上的)的密碼,而且運作良好。 但當我嘗試:

Invoke-Command -ComputerName server02 -ScriptBlock {Get-Culture} 

這也似乎工作。可能是因爲2臺服務器在同一個域中。雖然我只希望它能夠在您提供正確的憑據時發揮作用。有人可以幫我嗎?

+1

你可能已經擁有的權限來訪問服務器,它是使用您的憑據(打開PS的用戶) – 4c74356b41

回答

1

您可能是通過域管理員帳戶或帳戶在域管理員組中執行此操作。

在任何情況下,這是因爲您的帳戶在該計算機上有privelegies。

+0

是的,這是一個在整個域中的管理員帳戶,不僅在遠程服務器上。 – DenCowboy

1

用哪個用戶在server01上執行腳本?該用戶是否也在server02上擁有權限?如果您的用戶在Server01和Server02上管理員的許可,則沒有憑據neccessary ......(據我所知)

要檢查所提供的證書有效看看這裏: https://gallery.technet.microsoft.com/scriptcenter/Test-Credential-dda902c6

還是什麼像這樣:

$cred = Get-Credential #Read credentials 
$username = $cred.username 
$password = $cred.GetNetworkCredential().password 

# Get current domain using logged-on user's credentials 
$CurrentDomain = "LDAP://" + ([ADSI]"").distinguishedName 
$domain = New-Object System.DirectoryServices.DirectoryEntry($CurrentDomain,$UserName,$Password) 

if ($domain.name -eq $null) 
{ 
    write-host "Authentication failed - please verify your username and password." 
    exit #terminate the script. 
} 
else 
{ 
    write-host "Successfully authenticated with domain $domain.name" 
} 

其中發現這裏(但我沒有測試過): https://serverfault.com/questions/276098/check-if-user-password-input-is-valid-in-powershell-script