有没有一种简单的方法可以检查系统上是否启用了CredSSP?

时间:2013-09-23 21:27:21

标签: windows powershell windows-server wsman

我知道Get-WSManCredSSP功能;但是,此cmdlet在脚本中不能很好地工作。这将返回类似于以下内容的长字符串:

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的方法。

3 个答案:

答案 0 :(得分:4)

您是否可以考虑使用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

答案 1 :(得分:2)

我也在努力克服Get-WSManCredSSP输出的限制,并发现Victor Vogelpoel / Ravikanth Chaganti发现this helper script非常有帮助。

一些例子:

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

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

检查指定的客户端计算机是否已设置为委派:

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

答案 2 :(得分:0)

(不是为了取代Vogelpoel&amp; 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
}
相关问题