众所周知,为避免Powershell Remoting 出现Powershell Second Hop问题 ,需要设置CredSSP客户端和服务器设置。
例如
# On the client, aka the First Hop Server Enable-WSManCredSSP -Role "Client" -DelegateComputer "secondhop.example.com" # On the server, aka the Second Hop Server Enable-WSManCredSSP -Role "Server"
现在我可以PSRemote到“客户”服务器,并从那里访问“服务器”服务器上的资源。 一切顺利。
但是,这个环境比较庞大, 我想知道在很多机器上有效的“客户委托计算机” 。 我如何做到这一点?
我知道我可以(Get-WSManCredSSP)[0]获得客户端代理计算机列表。 但是这是一个丑陋,笨拙的string,我非常想不parsing ,因为这是Powershell,而且我爱上了面向对象的方法。
我想我认为我已经完成了wsman:/使用Get-Item和Get-Item Get-WSManInstance ,以及通过合理地search谷歌所必须的search引擎。
这似乎难以想象,这是如此难以捉摸,我一定错过了一些令人尴尬的简单。
因此,ServerFault, 我如何本机或使用直接的.NET调用Powershell得到一个给定的主机上的CredSSP客户端DelegateComputers一个很好的数组或类似 ?
我可以在Win2008r2和Win2012r2上运行任何版本的.NET Framework和Powershell。
事实certificate,谷歌实际上还有一个页面, 这就是答案隐藏的地方 。
客户端DelegateComputer列表存储在Windowsregistry中:
HKLM:\software\policies\microsoft\windows\CredentialsDelegation\AllowFreshCredentials
读这个关键不是很漂亮,但是比替代select要好。
所以,维克多·沃格尔波尔对他的世俗荣耀提出了以下的指引:
((Get-ItemProperty HKLM:\software\policies\microsoft\windows\CredentialsDelegation\AllowFreshCredentials).psobject.Properties | where { $_.Name -match "\d+" } | select -expand value | foreach { if ($_ -like "wsman/*") { $_.substring(6) } else { $_ } })