我们正尝试通过Powershell连接到远程服务器,并使用ActiveDirectory模块。 当试图在本地做到这一切,似乎一切正常。
PS C:\Users\bar> Import-Module ActiveDirectory PS C:\Users\bar> Get-ADUser 'baz' DistinguishedName : CN=Foo Baz,OU=baz.myhost.com,OU=FooMachine,DC=foo,DC=blah,DC=loc Enabled : True GivenName : Baz Name : Foo Baz ObjectClass : user ObjectGUID : <some guid> SamAccountName : baz SID : <more info here> Surname : Baz UserPrincipalName : baz@foo
当我们远程执行相同的操作时,我们并不那么幸运。
C:\> Enter-PSSession -ComputerName 172.1.2.3 -Credential foo\bar [172.1.2.3]: PS C:\Users\bar\Documents> Import-Module ActiveDirectory WARNING: Error initializing default drive: 'Unable to contact the server. This may be because this server does not exist, it is currently down, or it does not have the Active Directory Web Services running.'. [172.1.2.3]: PS C:\Users\bar\Documents> Get-ADUser 'baz' Unable to contact the server. This may be because this server does not exist, i t is currently down, or it does not have the Active Directory Web Services runn ing. + CategoryInfo : + FullyQualifiedErrorId : Unable to contact the server. This may be becaus e this server does not exist, it is currently down, or it does not have th e Active Directory Web Services running.,Microsoft.ActiveDirectory.Managem ent.Commands.GetADUser [172.1.2.3]: PS C:\Users\bar\Documents>
克里斯托弗,我们有2 – 2008 R2域控制器在该域中运行。 活动目录Web服务同时运行(“Import-Module ActiveDirectory”在服务器控制台上正常工作 – 它不是一个域控制器
在这种情况下,CREDSSP会被要求吗?
以下是使用CredSSP解决类似问题的示例。 我testing了这一点,它可以解决您在问题中发布的AD Web服务错误。
从文章中总结,首先您需要在客户端和服务器上启用CredSSP。
在客户端上: Enable-WSManCredSSP -Role Client -DelegateComputer [computer name] -Force
在服务器上: Enable-WSManCredSSP -Role Server –Force
接下来,您需要获取或使凭证连接到另一台计算机,并创build使用该凭证的会话。 然后,可以使用Invoke-Command在新会话的脚本块中运行PowerShell命令/脚本。 以下是本文的部分示例,使用您的问题中的命令:
$credential = Get-Credential -Credential iammred\administrator $session = New-PSSession -cn SQL1.Iammred.Net -Credential $credential -Authentication Credssp Invoke-Command -Session $session -ScriptBlock { Import-Module ActiveDirectory; Get-ADUser 'baz' }
但是,这会交互式地询问您的凭据,所以如果您想避免这种情况,您需要为$credential执行类似的操作:
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "DOMAIN\username",$pass;
其中$pass是与帐户关联的密码的安全string。
要使用AD模块,除了使用带有AD PowerShell模块的Server 2008 R2或Windows 7计算机之外,如果您没有运行Server 2008 R2 AD服务器,则需要这样做:
如果使用带有上述附件的Server 2003或2008 AD服务器,则仍然需要Server 2008 R2或Windows 7系统才能使用AD模块。 使用PowerShell远程处理,您将能够使用安装了PowerShell v2的任何系统远程调用AD模块cmdlet,如下所示:
您使用IP地址连接到服务器。 这样,Kerberos不能用于authentication(这就是为什么你必须使用凭据)。 所以,当服务器尝试代表您进行身份validation时,会遇到第二个跳跃问题。 服务器无法将凭据交给第三方,因此会出错。
您的scheme要求您通过Kerberos将客户端连接到服务器。 这是唯一可能的,如果你的客户是域成员,你使用服务器的名称,而不是它的IP地址。
Tobias http://www.powershell.com
我和我们的几个环境有同样的问题,有效的是防火墙的改变。 显然ADWS使用端口7389,这是不允许从试图远程pipe理DC使用PowerShell的服务器。 一旦我们允许港口,一切工作顺利。