2013-09-23 75 views
3

我知道Get-WSManCredSSP函数;但是,此cmdlet在脚本中效果不佳。这将返回类似于下面的长字符串:有没有简单的方法来检查系统上是否启用了CredSSP?

The machine is configured to allow delegating fresh credentials to the following target(s): wsman/*,wsman/*,wsman/*,wsman/* 
This computer is configured to receive credentials from a remote client computer. 

我不能轻易包括这是我写一个剧本,所以我在寻找一种替代的方法来检查的CredSSP。

回答

2

您不能考虑按照CmdLet help中的说明使用它:获取客户端上的WS-Management CredSSP设置(<localhost|computername>\Client\Auth\CredSSP)。

在本地机器它给出:

(Get-Item WSMan:\localhost\Client\Auth\CredSSP).value 

您可以使用它像这样:

(Get-Item WSMan:\localhost\Client\Auth\CredSSP).value -eq $false 

你可以先测试,如果WinRM的可用:

(Get-Service -Name winrm).Status 
+0

值得一提的是,这是对客户端启用的CredSSP。如果要检查服务器启用的CredSSP,请使用以下内容: (Get-Item WSMan:\ localhost \ Service \ Auth \ CredSSP).value – Anthony

2

我也在努力处理Get-WSManCredSSP输出的局限性,并发现了Victor的this helper script Vogelpoel/Ravikanth Chaganti会非常有帮助。

一些例子:

检查当前机器已被配置为CredSSP的服务器和/或客户端:

(Get-WSManCredSSPConfiguration).IsServer 
(Get-WSManCredSSPConfiguration).IsClient 

检查指定的客户端机器已经成立了代表团:

Get-WSManCredSSPConfiguration | % { $_.ClientDelegateComputer.Contains('clientcomputername') } 
0

(不打算替代Vogelpoel & Chaganti的工作,但作为快速阅读CredSSP.cs的快速总结,所以你可以得到什么它做一个快速的掌握 - 这么说,这是在几个系统我在手上测试,似乎工作)

function Get-WSManCredSSPState 
{ 
    $res = [pscustomobject]@{DelegateTo = @(); ReceiveFromRemote = $false} 

    $wsmTypes = [ordered]@{} 
    (gcm Get-WSManCredSSP).ImplementingType.Assembly.ExportedTypes ` 
    | %{$wsmTypes[$_.Name] = $_} 

    $wmc = new-object $wsmTypes.WSManClass.FullName 
    $wms = $wsmTypes.IWSManEx.GetMethod('CreateSession').Invoke($wmc, @($null,0,$null)) 
    $cli = $wsmTypes.IWSManSession.GetMethod('Get').Invoke($wms, @("winrm/config/client/auth", 0)) 
    $res.ReceiveFromRemote = [bool]([xml]$cli).Auth.CredSSP 

    $afcPath = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\CredentialsDelegation\AllowFreshCredentials' 
    if (test-path $afcPath) 
    { 
    $afc = gi $afcPath 
    $res.DelegateTo = $afc.GetValueNames() | sls '^\d+$' | %{$afc.GetValue($_)} 
    } 
    return $res 
} 
相关问题