Mic*_*ens 11 powershell remoting credssp winrm
在尝试使用远程处理创建 PowerShell 脚本时,我遇到了我认为的双跳问题。在那篇文章中,Perriman 简要描述了问题以及解决问题的具体步骤(如果您知道命令,那几乎是微不足道的,但对于像我这样不太熟悉的人来说,这些信息非常宝贵!)。
我Enable-WSManCredSSP Server
在我的 Win7 服务器上运行Enable-WSManCredSSP Client –DelegateComputer <FQDN of the server>
时没有发生任何意外,但尝试在我的 Win7 客户端上运行时产生了这个错误:
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".
Run Code Online (Sandbox Code Playgroud)
运行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.
Run Code Online (Sandbox Code Playgroud)
和GET-WSManCredSSP证实了我的服务器准备接受来自客户端凭证:
The machine is not configured to allow delegating fresh credentials.
This computer is configured to receive credentials from a remote client computer.
Run Code Online (Sandbox Code Playgroud)
我还发现了 Boessen关于 WinRM的文章,其中他描述了 WinRM 的一般设置,并找到了一个花絮来获得有用的诊断数据点;这个在客户端运行的命令使用winrs工具远程访问服务器:
winrs -r:http://<FQDN of my server>:5985 -u:<myDomain>\msorens "dir c:\"
Run Code Online (Sandbox Code Playgroud)
该命令返回了预期结果,即服务器上根目录的内容,没有意外,确认我的 FQDN 正确并且启用了 WinRM。
Boessen 表示 5985 端口是 Win7 的默认端口;在服务器上运行的此命令确认值为 5985:
get-item wsman:\localhost\listener\listener*\port
Run Code Online (Sandbox Code Playgroud)
问题:为什么我无法在客户端执行 Enable-WSManCredSSP 命令?
2011.06.07 更新
我找到了上述问题的解决方案:调用Enable-PSRemoting,宣传配置计算机以接收远程命令,允许客户端上的Enable-WSManCredSSP成功运行!很好奇,但它的手册页表明它执行了许多不同的操作,所以我假设其中一个不经意间做了我需要的操作。
但是当我尝试使用 CredSSP 身份验证时,我遇到了另一个障碍。这是命令:
Invoke-Command { Write-Host "hello, world" } -computername $serverName `
-credential $testCred -Authentication Credssp
Run Code Online (Sandbox Code Playgroud)
这是回应:
连接到远程服务器失败并显示以下错误消息: WinRM 客户端无法处理该请求。计算机策略不允许 将用户凭据委派给目标计算机。使用 gpedit.msc 并查看以下策略:计算机配置 -> 管理模板 -> 系统 -> 凭证委托 -> 允许委派新凭据。验证它是否已启用并且 配置了适合目标计算机的 SPN。例如, 对于目标计算机名称“myserver.domain.com”,SPN 可以是以下之一 以下内容:WSMAN /myserver.domain.com 或 WSMAN/*.domain.com。 有关详细信息,请参阅 about_Remote_Troubleshooting 帮助主题。
我按照这条非常有用的错误消息的建议验证了设置,在我看来它配置正确。
新问题:此与 CredSSP 的远程连接尝试失败了怎么办?
在回答时,请记住以下几点: 让我提前消除任何我知道我在这里做什么的想法,尽管有任何相反的表现。:-) Windows 管理不是我的专业领域!
在短暂的中断之后,我又回到了这个问题上,用新的眼光(我的和同事的)重新审视,并决定再次回到基础:
在我执行的客户端上(在管理员 shell 中):
enable-wsmancredssp -role client -delegatecomputer devremvm03 -force
Run Code Online (Sandbox Code Playgroud)
在我执行的服务器上(在管理员 shell 中):
enable-wsmancredssp -role server -force
Run Code Online (Sandbox Code Playgroud)
两者都返回正常输出,表明 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 Code Online (Sandbox Code Playgroud)
所有这些都在我的 run.ps1 脚本中,所以成绩单如下(这是在非管理员 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
Run Code Online (Sandbox Code Playgroud)
以前,只有 basic、remote 和 credentialA 有效。现在所有 5 个工作。哇!
归档时间: |
|
查看次数: |
66093 次 |
最近记录: |