Invoke-command不需要凭据

时间:2017-02-14 12:37:50

标签: powershell windows-server-2012 windows-server-2012-r2

我在同一个域中有2台服务器(Windows Server 2012 R2)。 我在server01上执行命令:

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

我提供管理员(服务器2)的密码,效果很好。 但是当我尝试:

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

它似乎也有效。可能是因为2台服务器位于同一个域中。虽然我只希望它可以提供正确的凭据。有人可以帮我吗?

2 个答案:

答案 0 :(得分:1)

您可能是通过Domain Admins帐户或Domain Admins组中的帐户执行此操作。

无论如何,这都是因为您的帐户在该计算机上具有privelegies。

答案 1 :(得分:1)

您在哪个用户上执行server01上的脚本?该用户是否也拥有server02的权限?如果您的用户在server01和server02上拥有管理员权限,那么就不需要凭据......(据我所知)

要查看提供的凭据是否有效,请查看此处: 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

相关问题