2017-02-14 40 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