在尝试使用远程创buildPowerShell脚本时,遇到了我认为是双跳问题 。 在那篇文章中,Perriman给出了这个问题的简洁描述以及解决这个问题的具体步骤(如果你知道命令,那么几乎是微不足道的,但是对于像我这样不那么熟悉的人来说,这个信息是非常宝贵的)。
我在Win7服务器上运行了Enable-WSManCredSSP Server ,但没有发生意外,但是试图在我的Win7客户端上运行Enable-WSManCredSSP Client –DelegateComputer <FQDN of the server>产生了这个错误:
Enable-WSManCredSSP : The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following com mand on the destination to analyze and configure the WinRM service: "winrm quickconfig".
运行winrm quickconfig确认我的服务器正在运行WinRM:
WinRM already is set up to receive requests on this machine. WinRM already is set up for remote management on this machine.
Get-WSManCredSSP证实我的服务器准备好接受来自客户端的证书:
The machine is not configured to allow delegating fresh credentials. This computer is configured to receive credentials from a remote client computer.
我还发现了Boessen 关于WinRM的文章,其中他描述了WinRM的一般设置,并发现了一个小技巧来获取有用的诊断数据。 在客户端上运行的这个命令使用winrs工具来远程访问服务器:
winrs -r:http://<FQDN of my server>:5985 -u:<myDomain>\msorens "dir c:\"
该命令返回了预期的结果,即服务器上根目录的内容,确保我的FQDN正确并且WinRM已启用。
Boessen指出端口5985是Win7的默认端口; 在服务器上运行此命令确认值5985:
get-item wsman:\localhost\listener\listener*\port
问题:为什么我无法在客户端执行Enable-WSManCredSSP命令?
2011.06.07更新
我find了一个解决上述问题的方法:调用Enable-PSRemoting ,通告configuration计算机接收远程命令,允许客户端上的Enable-WSManCredSSP工作成功! 好奇,但它的手册页表明它做了一些不同的行动,所以我认为其中一个无意中做了我所需要的。
但是当我尝试使用CredSSP身份validation时,我又到了另一个障碍。 这里是命令:
Invoke-Command { Write-Host "hello, world" } -computername $serverName ` -credential $testCred -Authentication Credssp
这里是回应:
连接到远程服务器失败,并显示以下错误消息: WinRM客户端无法处理请求。 计算机政策不允许 将用户凭据委托给目标计算机。 使用gpedit.msc 并看看以下策略:计算机configuration - >pipe理模板 - >系统 - >凭据委派 - >允许委派新的凭据。 validation它是否已启用 configuration适合目标计算机的SPN。 例如, 对于目标计算机名称“myserver.domain.com”,SPN可以是其中之一 如下所示:WSMAN /myserver.domain.com或WSMAN / *。domain.com。 有关更多信息,请参阅about_Remote_Troubleshooting帮助主题。
我validation了这个设置,正如这个非常有帮助的错误消息所build议的那样,而且在我看来,它是正确configuration的。
新的问题:这个远程连接尝试CredSSP失败了什么?
在回答时请记住以下几点: 让我提前解散我知道我在这里做什么的观念,尽pipe有任何相反的performance。:-) Windowspipe理员并不是我的专业领域!
我经过一段短暂的停顿后,又回到了这里,用新鲜的眼睛(我的和同事)再次看了一遍,然后又决定回到基本的地步:
在我执行的客户端上(在pipe理员shell中):
enable-wsmancredssp -role client -delegatecomputer devremvm03 -force
在我执行的服务器上(在pipe理员shell中):
enable-wsmancredssp -role server -force
这两个返回的正常输出表明CredSSP现在是“真”。
然后,我使用下面的练习代码来解决日益复杂的问题:
$block = { Write-Host ("hello, world: {0}, {1}" -f $env:USERNAME, (hostname)) } $username = "test_user" $password = "..." $adjPwd = $password | ConvertTo-SecureString -asPlainText -Force $testCred = (New-Object System.Management.Automation.PSCredential($username,$adjPwd)) switch ($choice) { "basic" { Invoke-Command $block } "remote" { Invoke-Command $block -computername $serverName } "credentialA" { Invoke-Command $block -computername $serverName -credential $testCred } "credentialB" { Invoke-Command $block -computername $serverName -credential $testCred -Authentication Credssp} "session" { $testSession = New-PSSession -computername $serverName -credential $testCred -Authentication Credssp if ($testSession) { Invoke-Command $block -Session $testSession; Remove-PSSession $testSession } } }
所有这一切都在我的run.ps1脚本,所以成绩单如下(并在非pipe理员shell程序中运行):
PS C:\> .\run.ps1 basic hello, world: msorens, MyLocalMachine PS C:\> .\run.ps1 remote MyRemoteServer hello, world: msorens, MyRemoteServer PS C:\> .\run.ps1 credentialA MyRemoteServer hello, world: test_user, MyRemoteServer PS C:\> .\run.ps1 credentialB MyRemoteServer hello, world: test_user, MyRemoteServer PS C:\> .\run.ps1 session MyRemoteServer hello, world: test_user, MyRemoteServer
以前,只有基本的,远程的和凭证A的工作。 现在所有5个工作。 呼!
当我不得不这样做时,这就是我所做的工作(也可能有一些GPO设置,但看起来你已经覆盖了这些设置)。
要使CLIENT能够使用CredSSP连接到域中的任何计算机:
Enable-WSManCredSSP -Role Client -DelegateComputer "*.my.domain.com" -Force | out-null #the following is used because -delegatecomputer (above) doesn't appear to actually work properly. Set-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Control\Lsa\Credssp\PolicyDefaults\AllowFreshCredentialsDomain -Name WSMan -Value "WSMAN/*.my.domain.com"
然后,我在每台目标机器(服务器)上运行以下命令启用CredSSP身份validation:
Connect-WSMan -ComputerName $computer Set-Item "WSMAN:\$computer\service\auth\credssp" -Value $true
这当然要求您以适当的权限运行脚本。 这对我有用 – 我希望它可以帮助你。
我得到了可以将虚拟机从一台hyper-v 2012R2服务器迁移到另一台服务器的位置,但无法将其迁移回去。 (我正在尝试使用SAMBA 4.2作为我的域控制器,并且想知道是否可以使用CredSSP进行实时迁移,因为我无法使用Samba4使用约束委派)。
最后,我去了工作的hyper-v,并将registry项在hklm:\ SOFTWARE \ Policies \ Microsoft \ Windows \ CredentialsDelegation中复制到非工作的hyper-v。 之后双方都做得很好。